#include <iostream> #include <cstdio> using namespace std; #define LL long long int main() { int n, m; scanf("%d %d", &n, &m); int grass[n]; LL grass_height[n]; for(int i = 0; i < n; ++i) { scanf("%d", &grass[i]); grass_height[i] = 0; } int current_day = 0; int day, height; for(int t = 0; t < m; ++t) { scanf("%d%d", &day, &height); LL sum = 0; for(int i = 0; i < n; ++i) { grass_height[i] += (LL)(day-current_day)*(LL)grass[i]; if(grass_height[i] > height) { sum += grass_height[i] - height; grass_height[i] = height; } } printf("%lld\n", sum); current_day = day; } 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 | #include <iostream> #include <cstdio> using namespace std; #define LL long long int main() { int n, m; scanf("%d %d", &n, &m); int grass[n]; LL grass_height[n]; for(int i = 0; i < n; ++i) { scanf("%d", &grass[i]); grass_height[i] = 0; } int current_day = 0; int day, height; for(int t = 0; t < m; ++t) { scanf("%d%d", &day, &height); LL sum = 0; for(int i = 0; i < n; ++i) { grass_height[i] += (LL)(day-current_day)*(LL)grass[i]; if(grass_height[i] > height) { sum += grass_height[i] - height; grass_height[i] = height; } } printf("%lld\n", sum); current_day = day; } return 0; } |