Submission #698039

#TimeUsernameProblemLanguageResultExecution timeMemory
698039hotboy2703Safety (NOI18_safety)C++14
100 / 100
236 ms20552 KiB
#include<bits/stdc++.h> using namespace std; long long n,h; long long s[200100]; int main(){ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); cin>>n>>h; for (long long i = 1;i <= n;i ++){ cin>>s[i]; } multiset <long long> l,r; long long add_l = 0,add_r = 0; long long a = 0; unsigned long long b = 0; for (long long i = 1;i <= n;i ++){ add_l -= h; add_r += h; b += h * a; a--; b += s[i]; l.insert(s[i] - add_l); l.insert(s[i] - add_l); while (!r.empty() && *l.rbegin() + add_l > *r.begin() + add_r){ long long tmp = *l.rbegin() + add_l; l.erase(l.find(*l.rbegin())); r.insert(tmp - add_r); } while (l.size() > r.size()){ long long tmp = *l.rbegin() + add_l; l.erase(l.find(*l.rbegin())); r.insert(tmp - add_r); } while (r.size() > l.size()){ long long tmp = *r.begin() + add_r; r.erase(r.find(*r.begin())); l.insert(tmp - add_l); } } for (auto x:l){ x += add_l; a++; b -= x; if (a == 0){ cout<<b<<'\n'; return 0; } } for (auto x:r){ x += add_r; a++; b -= x; if (a == 0){ cout<<b<<'\n'; return 0; } } return 0; }
#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...