Submission #197521

#TimeUsernameProblemLanguageResultExecution timeMemory
197521handlename지구 온난화 (NOI13_gw)C++17
40 / 40
244 ms22084 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; int arr[n]; for (int i=0;i<n;i++) cin>>arr[i]; if (n<2){ cout<<1; return 0; } vector<pair<int,bool> > peaks; //height,true=bottom,false=top bool increasing; if (arr[1]>arr[0]){ peaks.push_back(make_pair(arr[1],false)); increasing=true; } else { peaks.push_back(make_pair(arr[0],false)); peaks.push_back(make_pair(arr[1],true)); increasing=false; } for (int i=2;i<n;i++){ if (increasing){ if (arr[i]>=arr[i-1]){ peaks.pop_back(); peaks.push_back(make_pair(arr[i],false)); } else { peaks.push_back(make_pair(arr[i],true)); increasing=false; } } else { if (arr[i]<=arr[i-1]){ peaks.pop_back(); peaks.push_back(make_pair(arr[i],true)); } else { peaks.push_back(make_pair(arr[i],false)); increasing=true; } } } if (peaks.back().second==true) peaks.pop_back(); sort(peaks.begin(),peaks.end()); int total=0,maxi=0; for (int i=peaks.size()-1;i>=0;i--){ if (peaks[i].second) total--; else total++; maxi=max(maxi,total); } cout<<maxi; }
#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...