Submission #594611

#TimeUsernameProblemLanguageResultExecution timeMemory
594611penguinhackerSafety (NOI18_safety)C++17
3 / 100
13 ms2004 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; 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 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...