Submission #800165

#TimeUsernameProblemLanguageResultExecution timeMemory
800165antonSafety (NOI18_safety)C++17
100 / 100
95 ms5452 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> struct F{ priority_queue<int> s; int shift_val =0; void shift(int v){ shift_val += v; } int insert(int id){ int v =id-shift_val; ////cout<<"inserting "<<id<<endl; s.push(v); s.push(v); int res = s.top() +shift_val; s.pop(); return res; } } L, R; int n, h; signed main(){ cin>>n>>h; int res =0; int v; cin>>v; R.s.push(-v); L.s.push(v); R.shift(-h); L.shift(-h); int prev= v; for(int i = 1; i<n; i++){ cin>>v; int ls, rs; if(prev<v){ rs = R.insert(-v); res += abs(rs-(-v)); L.s.push(-rs-L.shift_val); } else{ ls = L.insert(v); res += abs(ls -v); R.s.push(-ls-R.shift_val); } R.shift(-h); L.shift(-h); prev= L.s.top() + R.shift_val; //cout<<res<<endl; } cout<<res<<endl; }
#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...