Submission #834468

#TimeUsernameProblemLanguageResultExecution timeMemory
834468uriegSafety (NOI18_safety)C++17
100 / 100
45 ms5404 KiB
#include<bits/stdc++.h> #define rall(x) x.rbegin(), x.rend() #define fi first #define se second #define ve vector typedef long long ll; using namespace std; int main(){ // ios_base::sync_with_stdio(0);cin.tie(0); ll n, a, h; priority_queue<ll>ql; priority_queue<ll, vector<ll>, greater<ll>>qr; long long ans = 0, h1=0,h2=0; scanf("%lld%lld%lld", &n, &h, &a); ql.push(a); qr.push(a); for(int i = 1; i<n; i++){ h1 -= h; h2 += h; scanf("%lld", &a); if(ql.top()+h1<a && a<qr.top()+h2){ ql.push(a-h1); qr.push(a-h2); } else if(a <= ql.top()+h1){ ans += ql.top()+h1 - a; ql.push(a-h1); ql.push(a-h1); qr.push(ql.top()+h1-h2); ql.pop(); } else if(qr.top()+h2 <= a){ ans += a - qr.top()-h2; qr.push(a-h2); qr.push(a-h2); ql.push(qr.top()+h2-h1); qr.pop(); } } cout<<ans; return 0; }

Compilation message (stderr)

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