Submission #863974

#TimeUsernameProblemLanguageResultExecution timeMemory
863974abcvuitunggioSafety (NOI18_safety)C++17
100 / 100
41 ms5492 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n,h,s,x,y,res; priority_queue <int> p,q; int32_t main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> n >> h; for (int i=0;i<n;i++){ cin >> s; x=i*h-s,y=s+i*h; if (p.empty()||x<p.top()){ p.push(x); p.push(x); res+=p.top()-x; q.push(i*h*2-p.top()); p.pop(); } else if (q.empty()||y<q.top()){ q.push(y); q.push(y); res+=q.top()-y; p.push(i*h*2-q.top()); q.pop(); } else{ p.push(x); q.push(y); } } cout << res; }
#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...