Submission #556975

#TimeUsernameProblemLanguageResultExecution timeMemory
5569751neSafety (NOI18_safety)C++14
0 / 100
122 ms14916 KiB
#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)

safety.cpp: In function 'int main()':
safety.cpp:15:9: warning: unused variable 'x' [-Wunused-variable]
   15 |    auto x = *maxxy.begin();
      |         ^
safety.cpp:12:20: warning: unused variable 'ans2' [-Wunused-variable]
   12 |  long long ans = 0,ans2 = 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...