Submission

Status:
[PPPPP][PPP][PPTSSSS]

Score: 50

User: pxsit

Problemset: 05.Two Towers

Language: cpp

Time: 1.094 second

Submitted On: 2025-04-17 11:09:51

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

struct Tower
{
    long long position;
    int height;

    Tower(long long p, int h) : position(p), height(h) {}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<Tower> towers;

    for (int i = 0; i < n; i++)
    {
        long long position;
        int height;
        cin >> position >> height;
        towers.push_back(Tower(position, height));
    }

    // Sort by height in descending order
    sort(towers.begin(), towers.end(), [](const Tower &a, const Tower &b)
         { return a.height > b.height; });

    long long maxArea = 0;
    vector<long long> positions;

    for (const auto &tower : towers)
    {
        long long pos = tower.position;
        int height = tower.height;

        // Find maximum width using current tower's height
        for (const auto &existingPos : positions)
        {
            long long width = abs(existingPos - pos);
            long long area = width * height;
            maxArea = max(maxArea, area);
        }

        // Add current position
        positions.push_back(pos);
    }

    cout << maxArea << endl;
    return 0;
}