Submission #594633

#TimeUsernameProblemLanguageResultExecution timeMemory
594633penguinhackerSafety (NOI18_safety)C++17
66 / 100
2059 ms1732 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=2e5; int n, h, a[mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> h; for (int i=0; i<n; ++i) cin >> a[i]; ll ans=0; vector<ll> v={a[0], a[0]}; for (int i=1; i<n; ++i) { for (int j=0; j<i; ++j) v[j]-=h, v[j+i]+=h; if (a[i]<v[i-1]) ans+=v[i-1]-a[i]; if (a[i]>v[i]) ans+=a[i]-v[i]; v.push_back(a[i]); v.push_back(a[i]); sort(v.begin(), v.end()); } cout << ans; 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...