#include <iostream> using namespace std; int main() { int n; int m; long long int sum=0; cin >> n; cin >> m; int a[n]; for(int counter=0; counter<n; counter++) cin >> a[counter]; long long int b[m]; long long int d[m]; long long int dlugosci[n]; for(int counter=0; counter<m; counter++) { cin >> d[counter]; cin >> b[counter]; } for(int counter=0; counter<n; counter++) { dlugosci[counter]=a[counter]*d[0]; if(dlugosci[counter]>b[0]) { sum=sum+dlugosci[counter]-b[0]; dlugosci[counter]=b[0]; } } cout << sum << endl; for(int counter1=1; counter1<m; counter1++) { sum=0; for(int counter=0; counter<n; counter++) { dlugosci[counter]=a[counter]*(d[counter1]-d[counter1-1])+dlugosci[counter]; if(dlugosci[counter]>b[counter1]) { sum=sum+dlugosci[counter]-b[counter1]; dlugosci[counter]=b[counter1]; } } cout << sum << 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 45 46 47 48 49 50 | #include <iostream> using namespace std; int main() { int n; int m; long long int sum=0; cin >> n; cin >> m; int a[n]; for(int counter=0; counter<n; counter++) cin >> a[counter]; long long int b[m]; long long int d[m]; long long int dlugosci[n]; for(int counter=0; counter<m; counter++) { cin >> d[counter]; cin >> b[counter]; } for(int counter=0; counter<n; counter++) { dlugosci[counter]=a[counter]*d[0]; if(dlugosci[counter]>b[0]) { sum=sum+dlugosci[counter]-b[0]; dlugosci[counter]=b[0]; } } cout << sum << endl; for(int counter1=1; counter1<m; counter1++) { sum=0; for(int counter=0; counter<n; counter++) { dlugosci[counter]=a[counter]*(d[counter1]-d[counter1-1])+dlugosci[counter]; if(dlugosci[counter]>b[counter1]) { sum=sum+dlugosci[counter]-b[counter1]; dlugosci[counter]=b[counter1]; } } cout << sum << endl; } return 0; } |