Submission #311268

#TimeUsernameProblemLanguageResultExecution timeMemory
311268kimbj0709Global Warming (NOI13_gw)C++14
40 / 40
265 ms25952 KiB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n;
  int input;
  cin >> n;
  vector<int> h = {-1};
  vector<int> vect1 = {-1};
  for(int i=0;i<n;i++){
    cin >> input;
    vect1.push_back(input);
  }
  for(int i=1;i<vect1.size();i++){
    if(vect1[i]!=vect1[i-1]){
      h.push_back(vect1[i]);
    }
  }
  h.push_back(-1);
  vector<pair<int,int> > sorted;
  for(int i=1;i<h.size()-1;i++){
    sorted.push_back({h[i],i});
  }
  sort(sorted.begin(),sorted.end());
  reverse(sorted.begin(),sorted.end());
  int curr = 0;
  int ans = 1;
  for(int i=0;i<sorted.size();){
    int current = sorted[i].f;
    while(i<sorted.size()&&sorted[i].f==current){
      int pos = sorted[i].s;
      if(h[pos-1]>current&&h[pos+1]>current){
        curr--;
      }
      else if(h[pos-1]<current&&h[pos+1]<current){
        curr++;
      }
      i++;
    }
    //cout << curr << "--\n";
    ans = max(ans,curr);
  }
  cout << ans;

}

Compilation message (stderr)

gw.cpp: In function 'int32_t main()':
gw.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for(int i=1;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
gw.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i=1;i<h.size()-1;i++){
      |               ~^~~~~~~~~~~
gw.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i=0;i<sorted.size();){
      |               ~^~~~~~~~~~~~~~
gw.cpp:33:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     while(i<sorted.size()&&sorted[i].f==current){
      |           ~^~~~~~~~~~~~~~
#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...