#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, m; cin>>n; cin>>m; int* speeds = new int[n]; int* areal = new int[n]; int* days = new int[m+1]; int* blades = new int[m]; for(int i = 0; i < n; i++){ cin>>speeds[i]; areal[i]=0; } days[0] = 0; for(int i = 0; i < m; i++){ cin>>days[i]; cin>>blades[i]; } for(int d = 0; d<m; d++){ int total = 0; for(int i = 0; i < n; i++){ total += max(areal[i]+(days[d+1]-days[d])*speeds[i]-blades[d],0); areal[i] = min(areal[i]+(days[d+1]-days[d])*speeds[i], blades[d]); } cout << total << 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, m; cin>>n; cin>>m; int* speeds = new int[n]; int* areal = new int[n]; int* days = new int[m+1]; int* blades = new int[m]; for(int i = 0; i < n; i++){ cin>>speeds[i]; areal[i]=0; } days[0] = 0; for(int i = 0; i < m; i++){ cin>>days[i]; cin>>blades[i]; } for(int d = 0; d<m; d++){ int total = 0; for(int i = 0; i < n; i++){ total += max(areal[i]+(days[d+1]-days[d])*speeds[i]-blades[d],0); areal[i] = min(areal[i]+(days[d+1]-days[d])*speeds[i], blades[d]); } cout << total << endl; } return 0; } |