#include <iostream> using namespace std; int n, m; const int stala = 500000; long long int szyb[stala], wys[stala], d[stala], b[stala]; long long int suma, roz; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for(int i = 0; i < n; i++) { cin >> szyb[i]; } for(int i = 1; i <= m; i++) { cin >> d[i] >> b[i]; } for(int i = 1; i <= m; i++) { roz = d[i]-d[i-1]; suma = 0; for(int j = 0; j < n; j++) { wys[j] += szyb[j]*roz; if(wys[j] > b[i]) { suma += wys[j]-b[i]; wys[j] = b[i]; } } cout << suma << "\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 | #include <iostream> using namespace std; int n, m; const int stala = 500000; long long int szyb[stala], wys[stala], d[stala], b[stala]; long long int suma, roz; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for(int i = 0; i < n; i++) { cin >> szyb[i]; } for(int i = 1; i <= m; i++) { cin >> d[i] >> b[i]; } for(int i = 1; i <= m; i++) { roz = d[i]-d[i-1]; suma = 0; for(int j = 0; j < n; j++) { wys[j] += szyb[j]*roz; if(wys[j] > b[i]) { suma += wys[j]-b[i]; wys[j] = b[i]; } } cout << suma << "\n"; } return 0; } |