// brute O(n*m) // #include <iostream> #include <cstdio> using llu = unsigned long long int; llu field[500002]; llu grow[500002]; int main() { // std::ios_base::sync_with_stdio(0); int n,m; scanf("%d %d", &n, &m); // std::cin >> n >> m; const int N = n; for(llu i = 0; i < N; i++) { scanf("%d", &grow[i]); } llu day_prev = 0; llu day_now = 0; llu height = 0; for(llu d = 0; d < m; d++) { scanf("%llu %llu", &day_now, &height); llu crop = 0; for (llu i = 0; i < N; i++) { field[i] += grow[i] * (day_now - day_prev); if (field[i] > height) { crop += field[i] - height; field[i] = height; } } day_prev = day_now; printf("%llu\n", crop); } 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 | // brute O(n*m) // #include <iostream> #include <cstdio> using llu = unsigned long long int; llu field[500002]; llu grow[500002]; int main() { // std::ios_base::sync_with_stdio(0); int n,m; scanf("%d %d", &n, &m); // std::cin >> n >> m; const int N = n; for(llu i = 0; i < N; i++) { scanf("%d", &grow[i]); } llu day_prev = 0; llu day_now = 0; llu height = 0; for(llu d = 0; d < m; d++) { scanf("%llu %llu", &day_now, &height); llu crop = 0; for (llu i = 0; i < N; i++) { field[i] += grow[i] * (day_now - day_prev); if (field[i] > height) { crop += field[i] - height; field[i] = height; } } day_prev = day_now; printf("%llu\n", crop); } return 0; } |