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>
#define ll long long
#define fi first
#define se second
using namespace std;
const int nmax = 200002;
int S[nmax], dup[nmax];
int main() {
int N,H;
cin >> N >> H;
for(int i=1; i<=N; i++) {
cin >> S[i];
dup[i]=S[i];
}
int idx=2;
int sem;
int cost = 0;
while(idx<=N) {
if(abs(dup[idx]-dup[idx-1])>H) {
sem = abs(dup[idx]-dup[idx-1])-H;
cost+=sem;
if(dup[idx] > dup[idx-1]) {
dup[idx]-=sem;
}
if(dup[idx] < dup[idx-1]) {
dup[idx]+=sem;
}
}
idx++;
}
cout << cost << endl;
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... |