#include <stdio.h> int main() { unsigned long long int n; unsigned long long int m; unsigned long long int tab[500000]; unsigned long long int growth_tempo[500000]; unsigned long long int d, b; unsigned long long int weight; unsigned long long int actual_day = 0; unsigned long long int previous_day = 1; unsigned long long int growth; unsigned long long int i, j; scanf("%lld", &n); scanf("%lld", &m); for(i = 0; i < n; ++i) { scanf("%lld", &tab[i]); growth_tempo[i] = tab[i]; } for(i = 0; i < m; ++i) { scanf("%lld", &d); scanf("%lld", &b); weight = 0; actual_day = d; growth = (actual_day - previous_day); for(j = 0; j < n; ++j) { tab[j] = tab[j] + growth * growth_tempo[j]; if(tab[j] > b) { weight = weight + (tab[j] - b); tab[j] = b; } } previous_day = actual_day; printf("%lld\n", weight); } }
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 | #include <stdio.h> int main() { unsigned long long int n; unsigned long long int m; unsigned long long int tab[500000]; unsigned long long int growth_tempo[500000]; unsigned long long int d, b; unsigned long long int weight; unsigned long long int actual_day = 0; unsigned long long int previous_day = 1; unsigned long long int growth; unsigned long long int i, j; scanf("%lld", &n); scanf("%lld", &m); for(i = 0; i < n; ++i) { scanf("%lld", &tab[i]); growth_tempo[i] = tab[i]; } for(i = 0; i < m; ++i) { scanf("%lld", &d); scanf("%lld", &b); weight = 0; actual_day = d; growth = (actual_day - previous_day); for(j = 0; j < n; ++j) { tab[j] = tab[j] + growth * growth_tempo[j]; if(tab[j] > b) { weight = weight + (tab[j] - b); tab[j] = b; } } previous_day = actual_day; printf("%lld\n", weight); } } |