제출 #1345107

#제출 시각아이디문제언어결과실행 시간메모리
1345107yumemystery지구 온난화 (NOI13_gw)C++20
40 / 40
132 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.rbegin(),A.rend());
	
	if (n == 1) cout << 1;
	else {
		vector<bool>used(n,0);
		int component = 0;
		int ans = 0;
		int j = 0;
		for (auto &h : A) {
			int a = h.first;

			while (j < n && A[j].first >= a) {
				int i = A[j].second;

				bool left = (i-1 >= 0 && used[i-1]);
				bool right = (i+1 < n && used[i+1]);

				if (left && right) --component;
				else if (!left && !right) ++component;
				
				used[i] = 1;

				++j;
			}
			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...