#include <iostream> using namespace std; int n, m; int a[500000], d[500000], b[500000]; int x[500000]; int s[500000]; int main(){ cin >> n; cin >> m; for (int i = 0; i < n; i++){ cin >> a[i]; } for (int i = 0; i < m; i++){ cin >> d[i]; cin >> b[i]; } for (int i = 0, j = 1; i < m; i++){ s[i] = 0; for (j; j <= d[i]; j++){ for (int k = 0; k < n; k++){ x[k] += a[k]; } } for (int k = 0; k < n; k++){ if ((x[k] - b[i]) > 0){ s[i] += x[k] - b[i]; x[k] = b[i]; } } } for (int i = 0; i < m; i++){ cout << s[i] << endl; } }
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; int n, m; int a[500000], d[500000], b[500000]; int x[500000]; int s[500000]; int main(){ cin >> n; cin >> m; for (int i = 0; i < n; i++){ cin >> a[i]; } for (int i = 0; i < m; i++){ cin >> d[i]; cin >> b[i]; } for (int i = 0, j = 1; i < m; i++){ s[i] = 0; for (j; j <= d[i]; j++){ for (int k = 0; k < n; k++){ x[k] += a[k]; } } for (int k = 0; k < n; k++){ if ((x[k] - b[i]) > 0){ s[i] += x[k] - b[i]; x[k] = b[i]; } } } for (int i = 0; i < m; i++){ cout << s[i] << endl; } } |