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;
#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 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... |