제출 #1164445

#제출 시각아이디문제언어결과실행 시간메모리
1164445son2008Safety (NOI18_safety)C++20
0 / 100
9 ms1348 KiB
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, H; cin >> N >> H; vector<long long> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; } if (N == 0) { cout << 0 << endl; return 0; } long long prev = S[0]; long long sum = 0; for (int i = 1; i < N; ++i) { long long low = prev - H; long long high = prev + H; long long current = S[i]; long long new_val; if (current < low) { new_val = low; } else if (current > high) { new_val = high; } else { new_val = current; } sum += abs(new_val - current); prev = new_val; } cout << sum << 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...