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 int long long
signed main(){
int n,m,ans=0; cin>>n>>m;
int arr[n+1];
for(int i=1;i<=n;i++) cin>>arr[i];
for(int i=2;i<=n;i++){
if(abs(arr[i]-arr[i-1])>m){
ans+=(abs(arr[i]-arr[i-1])-m);
if(arr[i]>arr[i-1]) arr[i]-=(abs(arr[i]-arr[i-1])-m);
else arr[i]+=(abs(arr[i]-arr[i-1])-m);
}
}
cout<<ans;
}
# | 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... |