Submission #569906

#TimeUsernameProblemLanguageResultExecution timeMemory
569906athensclubGlobal Warming (NOI13_gw)C++14
40 / 40
446 ms18588 KiB
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    pair<int, int> arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i].first;
        arr[i].second = i;
    }

    sort(arr, arr + n);
    int maxx = 0, current = 0;
    bool land[n] = {0};
    for (int i = n - 1; i >= 0; i--)
    {
        int height = arr[i].first, index = arr[i].second;
        land[index] = true;
        if (index - 1 >= 0 && land[index - 1] && index + 1 < n && land[index + 1])
        {
            current--;
        }
        else if ((index - 1 >= 0 && land[index - 1]) || (index + 1 < n && land[index + 1]))
        {
            // append current land to the island connected to it, no. of island stays the same
        }
        else
        {
            current++;
        }

        if(i == 0 || height != arr[i-1].first)
            maxx = max(maxx, current);
    }
    cout << maxx << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...