#include <bits/stdc++.h> int main() { int n, m, limit; int tab[500001], growth[500001]; scanf("%d %d", &n, &m); for(int i=0; i<n; i++) { scanf("%d", &tab[i]); growth[i] = tab[i]; } while(m--) { long long profit = 0; scanf("%*d %d", &limit); for(int i=0; i<n; i++) { if(tab[i] > limit) { profit += (tab[i]-limit); tab[i] = limit; } tab[i] += growth[i]; } printf("%lld\n", profit); } 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 | #include <bits/stdc++.h> int main() { int n, m, limit; int tab[500001], growth[500001]; scanf("%d %d", &n, &m); for(int i=0; i<n; i++) { scanf("%d", &tab[i]); growth[i] = tab[i]; } while(m--) { long long profit = 0; scanf("%*d %d", &limit); for(int i=0; i<n; i++) { if(tab[i] > limit) { profit += (tab[i]-limit); tab[i] = limit; } tab[i] += growth[i]; } printf("%lld\n", profit); } return 0; } |