#include <iostream> #include <sstream> #define SIZE 200000 int main() { int n,m; std::cin >> n; std::cin >> m; long long customers[SIZE]; long long prev = 0; for (int i=0; i<n; ++i) { long long t; std::cin >> t; customers[i] = t - prev; prev = t; } std::stringstream result; for (int i=0; i<m; ++i) { long long overflow = 0, sum = 0, t; std::cin >> t; for (int j=0; j<n; ++j) { if (t + overflow > customers[j]) { long long newOverflow = t + overflow - customers[j]; sum += newOverflow; overflow = newOverflow; } else { overflow = 0; } } result << sum << std::endl; } std::cout << result.str(); 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 | #include <iostream> #include <sstream> #define SIZE 200000 int main() { int n,m; std::cin >> n; std::cin >> m; long long customers[SIZE]; long long prev = 0; for (int i=0; i<n; ++i) { long long t; std::cin >> t; customers[i] = t - prev; prev = t; } std::stringstream result; for (int i=0; i<m; ++i) { long long overflow = 0, sum = 0, t; std::cin >> t; for (int j=0; j<n; ++j) { if (t + overflow > customers[j]) { long long newOverflow = t + overflow - customers[j]; sum += newOverflow; overflow = newOverflow; } else { overflow = 0; } } result << sum << std::endl; } std::cout << result.str(); return 0; } |