This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |