#include <iostream> #include <vector> #include <algorithm> int main(int argc, char *argv[]) { int howlong; int howbig; std::cin >> howbig >> howlong; std::vector<unsigned long long> height(howbig, 0); std::vector<unsigned long long> growth(howbig, 0); for (int i = 0; i < growth.size(); ++i) std::cin >> growth[i]; unsigned long long day = 0; unsigned long long d; unsigned long long l; unsigned long long howmuch; while (howlong--) { howmuch = 0; std::cin >> d >> l; for (int i = 0; i < height.size(); ++i) height[i] += growth[i] * (d - day); for (int i = 0; i < height.size(); ++i) { howmuch += (height[i] > l) ? height[i] - l : 0; height[i] = (height[i] > l)? l : height[i]; } day = d; std::cout << howmuch << std::endl; } 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 | #include <iostream> #include <vector> #include <algorithm> int main(int argc, char *argv[]) { int howlong; int howbig; std::cin >> howbig >> howlong; std::vector<unsigned long long> height(howbig, 0); std::vector<unsigned long long> growth(howbig, 0); for (int i = 0; i < growth.size(); ++i) std::cin >> growth[i]; unsigned long long day = 0; unsigned long long d; unsigned long long l; unsigned long long howmuch; while (howlong--) { howmuch = 0; std::cin >> d >> l; for (int i = 0; i < height.size(); ++i) height[i] += growth[i] * (d - day); for (int i = 0; i < height.size(); ++i) { howmuch += (height[i] > l) ? height[i] - l : 0; height[i] = (height[i] > l)? l : height[i]; } day = d; std::cout << howmuch << std::endl; } return 0; } |