Submission #170352

#TimeUsernameProblemLanguageResultExecution timeMemory
170352ngmhGlobal Warming (NOI13_gw)C++11
40 / 40
839 ms31292 KiB
#include <bits/stdc++.h> using namespace std; int n, a[1000000], h = 0, c = -1, t = 0, l = 0; vector<pair<int, int> > pv, is; int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; if(n > 1){ if(a[0] > a[1]) pv.push_back(make_pair(a[0], 1)); if(a[n-1] > a[n-2]) pv.push_back(make_pair(a[n-1], 1)); } for(int i = 1; i < n-1; i++){ if(a[i-1] > a[i]){ while(a[i] == a[i+1]) i++; if(a[i] < a[i+1]) pv.push_back(make_pair(a[i], -1)); } else if(a[i-1] < a[i]){ while(a[i] == a[i+1]) i++; if(a[i] > a[i+1]) pv.push_back(make_pair(a[i], 1)); } } sort(pv.begin(), pv.end()); reverse(pv.begin(), pv.end()); for(int i = 0; i < pv.size(); i++){ if(pv[i].first == c) t += pv[i].second; else { if(c != -1) is.push_back(make_pair(c, t)); c = pv[i].first; t = pv[i].second; } } for(int i = 0; i < is.size(); i++){ l += is[i].second; h = max(h, l); } cout << h; }

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < pv.size(); i++){
                    ~~^~~~~~~~~~~
gw.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < is.size(); i++){
                    ~~^~~~~~~~~~~
#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...