Submission #559801

#TimeUsernameProblemLanguageResultExecution timeMemory
559801krit3379Safety (NOI18_safety)C++17
100 / 100
56 ms5380 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define N 200005 typedef long long ll; ll x,h,shift,ymin; priority_queue<ll> l; priority_queue<ll,vector<ll>,greater<ll>> r; int main(){ int n; scanf("%d %lld",&n,&h); scanf("%lld",&x); l.push(x),r.push(x); while(--n){ scanf("%lld",&x); shift+=h; if(x<l.top()-shift){ ymin+=l.top()-shift-x; r.push(l.top()-2*shift); l.pop(); l.push(x+shift); l.push(x+shift); } else if(x>r.top()+shift){ ymin+=x-r.top()-shift; l.push(r.top()+2*shift); r.pop(); r.push(x-shift); r.push(x-shift); } else{ l.push(x+shift); r.push(x-shift); } } printf("%lld",ymin); return 0; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %lld",&n,&h);
      |     ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%lld",&x);
      |     ~~~~~^~~~~~~~~~~
safety.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         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...