Submission #1345102

#TimeUsernameProblemLanguageResultExecution timeMemory
1345102yumemysteryGlobal Warming (NOI13_gw)C++20
23 / 40
131 ms8268 KiB
#include <bits/stdc++.h>
using namespace std;

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

	int n;
	cin >> n;

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

	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());

	vector<bool>used(n,0);
	
	if (n == 1) cout << 1;
	else {
		int component = 0;
		int ans = 0;

		for (auto &a : A) {
			int i = a.second;

			if (i+1 < n) {
				if (i-1 >= 0) {
					if (!used[i-1] && !used[i+1]) {
						++component;
					}
					if (used[i-1] && used[i+1]) {
						--component;
					}
				}
				else {
					if (!used[i+1]) ++component;
				}
			}
			else {
				if (!used[i-1]) ++component;
			}

			used[i] = 1;

			ans = max(ans,component);
		}

		cout << ans;
	}
}
#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...