Submission #387518

#TimeUsernameProblemLanguageResultExecution timeMemory
387518CaroLindaSafety (NOI18_safety)C++14
100 / 100
95 ms5640 KiB
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define mk make_pair #define pii pair<int,int> #define sz(x) (int)(x.size()) #define mkt make_tuple #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define debug printf const int MAXN = 2e5+10 ; using namespace std ; int N ; ll H , a ,b ; priority_queue<ll> lef ; priority_queue< ll , vector<ll>, greater<ll> > rig ; ll lzLef , lzRig ; void print() { debug("y = x*%lld + %lld\n", a , b ); vector<ll> l , r ; while( !rig.empty() ) { r.pb( rig.top() ) ; rig.pop() ; } while(!lef.empty()) { l.pb( lef.top() ) ; lef.pop() ; } for(auto e : r ) rig.push(e) ; for(auto e : l ) lef.push(e) ; for(int i = sz(l)-1 ; i >= 0 ; i-- ) debug("%lld ", l[i]+lzLef ) ; debug("---- ") ; for(auto e : r ) debug("%lld " , e+lzRig ) ; debug("\n") ; } int main() { scanf("%d %lld", &N, &H ) ; for(int i = 1 ; i <= N ; i++ ) { ll x ; scanf("%lld", &x ) ; a++ ; b -= x ; if(lef.empty()) { assert(i == 1 ) ; lef.push(x) ; rig.push(x); } else { if( x >= lef.top()+lzLef ) { rig.push( x-lzRig ) ; rig.push( x-lzRig ) ; lef.push( rig.top()+lzRig-lzLef ) ; rig.pop() ; } else { lef.push(x-lzLef) ; lef.push( x-lzLef ) ; rig.push( lef.top()+lzLef-lzRig ) ; lef.pop() ; } } //print() ; //debug("\n") ; lzLef -= H ; lzRig += H ; b -= a*H ; //print() ; //debug("\n\n") ; } while( !rig.empty() ) { ll p = rig.top()+lzRig ; rig.pop() ; b += p ; a-- ; } printf("%lld\n" , b ) ; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |  scanf("%d %lld", &N, &H ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
safety.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |   scanf("%lld", &x ) ;
      |   ~~~~~^~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...