#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 |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1316 KB |
Output is correct |
2 |
Correct |
25 ms |
1356 KB |
Output is correct |
3 |
Correct |
25 ms |
1316 KB |
Output is correct |
4 |
Correct |
24 ms |
1364 KB |
Output is correct |
5 |
Correct |
31 ms |
1308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
1948 KB |
Output is correct |
2 |
Correct |
30 ms |
1740 KB |
Output is correct |
3 |
Correct |
42 ms |
1868 KB |
Output is correct |
4 |
Correct |
42 ms |
1944 KB |
Output is correct |
5 |
Correct |
42 ms |
1892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
18344 KB |
Output is correct |
2 |
Correct |
440 ms |
18344 KB |
Output is correct |
3 |
Correct |
441 ms |
18344 KB |
Output is correct |
4 |
Correct |
446 ms |
18588 KB |
Output is correct |
5 |
Correct |
431 ms |
17688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
17684 KB |
Output is correct |
2 |
Correct |
443 ms |
17696 KB |
Output is correct |
3 |
Correct |
442 ms |
17740 KB |
Output is correct |
4 |
Correct |
270 ms |
11848 KB |
Output is correct |
5 |
Correct |
266 ms |
11928 KB |
Output is correct |