#include <iostream> using namespace std; int main() { long long n, m, now = 0, d, b, w, i, j; long long *tab1, *tab2; cin >> n >> m; tab1 = new long long[n]; tab2 = new long long[n]; for(i = 0; i < n; i++) { cin >> tab1[i]; } for(i = 0; i < m; i++) { cin >> d >> b; w = 0; for (int j = 0; j < n; j++) { tab2[j] += tab1[j] * (d - now); if (tab2[j] > b) { w += tab2[j] - b; tab2[j] = b; } } now = d; cout << w << endl; } delete [] tab1; delete [] tab2; 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 | #include <iostream> using namespace std; int main() { long long n, m, now = 0, d, b, w, i, j; long long *tab1, *tab2; cin >> n >> m; tab1 = new long long[n]; tab2 = new long long[n]; for(i = 0; i < n; i++) { cin >> tab1[i]; } for(i = 0; i < m; i++) { cin >> d >> b; w = 0; for (int j = 0; j < n; j++) { tab2[j] += tab1[j] * (d - now); if (tab2[j] > b) { w += tab2[j] - b; tab2[j] = b; } } now = d; cout << w << endl; } delete [] tab1; delete [] tab2; return 0; } |