#include <iostream> using namespace std; using LLU = long long unsigned int; int n, m, t, d; LLU customers[200000]; inline LLU calc(const LLU d) { LLU sum = 0; LLU last = 0; for(int c=0; c<n; ++c) { const LLU t = customers[c]; last += d; if(last <= t) { last = t; } else { sum += last - t; } } return sum; } int main() { std::ios_base::sync_with_stdio(false); cin >> n >> m; for(int i=0; i<n; ++i) cin >> customers[i]; for(int i=0; i<m; ++i) { cin >> d; cout << calc(d) << endl; } 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 <iostream> using namespace std; using LLU = long long unsigned int; int n, m, t, d; LLU customers[200000]; inline LLU calc(const LLU d) { LLU sum = 0; LLU last = 0; for(int c=0; c<n; ++c) { const LLU t = customers[c]; last += d; if(last <= t) { last = t; } else { sum += last - t; } } return sum; } int main() { std::ios_base::sync_with_stdio(false); cin >> n >> m; for(int i=0; i<n; ++i) cin >> customers[i]; for(int i=0; i<m; ++i) { cin >> d; cout << calc(d) << endl; } return 0; } |