// Arkadiusz Roussau
// PO2017 - Zapiekanki 2 [B]
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const long long N = 200100;
long long n, m, customer_time[N], t, d;
long long solve(long long d) {
long long current_time = 0;
long long res = 0;
for (long long i = 0; i < n; ++i) {
current_time += d;
if (current_time > customer_time[i]) {
res += current_time - customer_time[i];
}
else {
current_time = customer_time[i];
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (long long i = 0; i < n; ++i) {
cin >> t;
customer_time[i] = t;
}
for (long long i = 0; i < m; ++i) {
cin >> d;
cout << solve(d) << "\n";
}
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 45 | // Arkadiusz Roussau // PO2017 - Zapiekanki 2 [B] #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const long long N = 200100; long long n, m, customer_time[N], t, d; long long solve(long long d) { long long current_time = 0; long long res = 0; for (long long i = 0; i < n; ++i) { current_time += d; if (current_time > customer_time[i]) { res += current_time - customer_time[i]; } else { current_time = customer_time[i]; } } return res; } int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (long long i = 0; i < n; ++i) { cin >> t; customer_time[i] = t; } for (long long i = 0; i < m; ++i) { cin >> d; cout << solve(d) << "\n"; } return 0; } |
English