#include <bits/stdc++.h> using namespace std; typedef long long ll; static inline ll SumAll(std::vector<ll>& times, int time) { ll sumAll = 0; ll prevTime = max(times.front() - time, 0LL); for (auto v: times) { ll tempV = prevTime + time; if (tempV < v) prevTime = v; else prevTime = tempV; sumAll += prevTime - v; } return sumAll; } int main() { ios::sync_with_stdio(0); int clients, fires; cin >> clients >> fires; vector<ll> times(clients); for (auto& v: times) cin >> v; while(fires--) { int v = 0; cin >> v; printf("%lld\n", SumAll(times, v)); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <bits/stdc++.h> using namespace std; typedef long long ll; static inline ll SumAll(std::vector<ll>& times, int time) { ll sumAll = 0; ll prevTime = max(times.front() - time, 0LL); for (auto v: times) { ll tempV = prevTime + time; if (tempV < v) prevTime = v; else prevTime = tempV; sumAll += prevTime - v; } return sumAll; } int main() { ios::sync_with_stdio(0); int clients, fires; cin >> clients >> fires; vector<ll> times(clients); for (auto& v: times) cin >> v; while(fires--) { int v = 0; cin >> v; printf("%lld\n", SumAll(times, v)); } return 0; } |