#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
int n, m;
cin >> n;
cin >> m;
int* height = (int*) malloc(n * sizeof(int));
int* growth = (int*) malloc(m * sizeof(int));
int* result = (int*) malloc(m * sizeof(int));
for (int i = 0; i < m; ++i) {
cin >> growth[i];
height[i] = 0;
}
int hay = 0;
int last_day = 0;
int day, cut, day_delta;
for (int i = 0; i < m; ++i) {
hay = 0;
cin >> day;
cin >> cut;
day_delta = day - last_day;
last_day = day;
for (int j = 0; j < n; ++j) {
int curr = growth[j] * day_delta + height[j];
hay += max(0, curr - cut);
height[j] = min(curr, cut);
}
result[i] = hay;
}
for (int i = 0; i < m; ++i) {
cout << result[i] << "\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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream> #include <algorithm> using namespace std; int main(int argc, char const *argv[]) { int n, m; cin >> n; cin >> m; int* height = (int*) malloc(n * sizeof(int)); int* growth = (int*) malloc(m * sizeof(int)); int* result = (int*) malloc(m * sizeof(int)); for (int i = 0; i < m; ++i) { cin >> growth[i]; height[i] = 0; } int hay = 0; int last_day = 0; int day, cut, day_delta; for (int i = 0; i < m; ++i) { hay = 0; cin >> day; cin >> cut; day_delta = day - last_day; last_day = day; for (int j = 0; j < n; ++j) { int curr = growth[j] * day_delta + height[j]; hay += max(0, curr - cut); height[j] = min(curr, cut); } result[i] = hay; } for (int i = 0; i < m; ++i) { cout << result[i] << "\n"; } return 0; } |
English