#include <iostream> #include <vector> using namespace std; typedef long long LL; #define INF 1000000000003LL struct data { double value; int count; int pos; data(double v, int c, int p): value(v), count(c), pos(p) {} }; int main() { int n, m; cin >> n >> m; vector<LL> t(n + 1); for (int i = 1; i <= n; i++) { cin >> t[i]; } LL d; for (int i = 0; i < m; i++) { cin >> d; LL sum = 0; LL r = 0; for (int j = 1; j <= n; j++) { r = (t[j] - t[j-1]) - d + r; if (r < 0) sum -= r; else r = 0; } cout << sum << endl; } }
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 | #include <iostream> #include <vector> using namespace std; typedef long long LL; #define INF 1000000000003LL struct data { double value; int count; int pos; data(double v, int c, int p): value(v), count(c), pos(p) {} }; int main() { int n, m; cin >> n >> m; vector<LL> t(n + 1); for (int i = 1; i <= n; i++) { cin >> t[i]; } LL d; for (int i = 0; i < m; i++) { cin >> d; LL sum = 0; LL r = 0; for (int j = 1; j <= n; j++) { r = (t[j] - t[j-1]) - d + r; if (r < 0) sum -= r; else r = 0; } cout << sum << endl; } } |