Submission #1023159

#TimeUsernameProblemLanguageResultExecution timeMemory
1023159avighnaGlobal Warming (NOI13_gw)C++17
40 / 40
164 ms21664 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> h(n); vector<pair<int, int>> hsort(n); vector<bool> present(n, true); for (int i = 0; i < n; ++i) { cin >> h[i]; hsort[i].first = h[i]; hsort[i].second = i; } sort(hsort.begin(), hsort.end()); if (n == 1) { cout << "1\n"; return 0; } int ans = 1, isl = 1; for (int i = 0; i < n; ++i) { if (i != 0 && hsort[i].first != hsort[i - 1].first) { ans = max(ans, isl); } int idx = hsort[i].second; present[idx] = false; if (idx == 0) { isl -= !present[1]; continue; } if (idx == n - 1) { isl -= !present[n - 2]; continue; } if (!present[idx - 1] && !present[idx + 1]) { isl--; continue; } if (present[idx - 1] && present[idx + 1]) { isl++; continue; } } ans = max(ans, isl); cout << ans << "\n"; }
#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...