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;
int l=a[0], r=a[0];
for (int i=1; i<n; ++i) {
l-=h, r+=h;
if (l<=a[i]&&a[i]<=r) {
l=r=a[i];
} else if (a[i]<l) {
ans+=l-a[i];
r=l, l=a[i];
} else {
assert(a[i]>r);
ans+=a[i]-r;
l=r, r=a[i];
}
}
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... |