// Michal Zagorski // Siano [A] #include <cstdio> #include <vector> #include <iostream> using namespace std; typedef unsigned long long int ulli; int main(){ int n = 0; ulli m = 0LL; scanf("%d %llu", &n, &m); std::vector<int> grass(n); std::vector <ulli> cutting(n, 0); int g = 0; for(int i = 0 ; i < n ; i++){ scanf("%d", &g); grass[i] = g; } ulli day = 0; for(ulli i = 0LL; i < m; i++){ ulli result = 0; ulli a,b; scanf("%llu %llu", &a, &b); ulli duration = a - day; day = a; for(int j = 0; j < n; j++){ ulli grow = cutting[j] + duration*grass[j]; cutting[j] = ((b > grow) ? grow : b ); if(b < grow){ result += (grow - b); } } printf("%llu\n", result); } 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 | // Michal Zagorski // Siano [A] #include <cstdio> #include <vector> #include <iostream> using namespace std; typedef unsigned long long int ulli; int main(){ int n = 0; ulli m = 0LL; scanf("%d %llu", &n, &m); std::vector<int> grass(n); std::vector <ulli> cutting(n, 0); int g = 0; for(int i = 0 ; i < n ; i++){ scanf("%d", &g); grass[i] = g; } ulli day = 0; for(ulli i = 0LL; i < m; i++){ ulli result = 0; ulli a,b; scanf("%llu %llu", &a, &b); ulli duration = a - day; day = a; for(int j = 0; j < n; j++){ ulli grow = cutting[j] + duration*grass[j]; cutting[j] = ((b > grow) ? grow : b ); if(b < grow){ result += (grow - b); } } printf("%llu\n", result); } return 0; } |