Submission #623415

#TimeUsernameProblemLanguageResultExecution timeMemory
623415PoonYaPatSafety (NOI18_safety)C++14
0 / 100
15 ms2000 KiB
#include <bits/stdc++.h> using namespace std; int n,k,a[200001],h[200001],mmax,mm; long long ans,sum; map<int,int> cnt; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>k; for (int i=1; i<=n; ++i) cin>>h[i],sum+=h[i]; sum/=n; if (k==0) { for (int i=1; i<=n; ++i) ans+=abs(sum-h[i]); cout<<ans; return 0; } a[n]=h[n]; for (int i=n; i>1; --i) { if (a[i]-h[i-1]>k) a[i-1]=a[i]-k; else if (h[i-1]-a[i]>k) a[i-1]=a[i]+k; else a[i-1]=h[i-1]; ans+=abs(a[i-1]-h[i-1]); } cout<<ans; }
#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...