Submission #830468

#TimeUsernameProblemLanguageResultExecution timeMemory
830468vjudge1Safety (NOI18_safety)C++17
0 / 100
38 ms2568 KiB
#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 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...