# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556975 | 1ne | Safety (NOI18_safety) | C++14 | 122 ms | 14916 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;cin>>n>>k;
vector<long long>arr(n);
for (int i = 0;i<n;++i)cin>>arr[i];
multiset<long long,greater<long long>>maxxy;
multiset<long long>minny;
long long ans = 0,ans2 = 0;
for (int i = 0;i<n;++i){
if (!maxxy.empty()){
auto x = *maxxy.begin();
auto y = *minny.begin();
if (abs(y - arr[i])>k){
ans+=abs(y - arr[i]) - k;
minny.erase(minny.begin());
minny.insert(min(y + k,arr[i]));
}
}
maxxy.insert(arr[i]);
minny.insert(arr[i]);
}
cout<<ans<<'\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |