// Karol Kosinski #include <cstdio> #define FOR(i,a,b) for(int i=(a);i<(b);++i) using namespace std; typedef long long LG; const int MX = 200003; LG T[MX]; int D[MX]; int n, m; void query(int d) { LG leftBorder = 0; LG res = 0; FOR(k,0,n) { LG waiting = leftBorder - T[k] + d; if (0 < waiting) { res += waiting; leftBorder += d; } else { leftBorder = T[k]; } } printf("%lld\n", res); } int main() { scanf("%d%d", &n, &m); FOR(i,0,n) scanf("%lld", T + i); FOR(i,0,m) scanf("%d", D + i); FOR(i,0,m) { query(D[i]); } 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 | // Karol Kosinski #include <cstdio> #define FOR(i,a,b) for(int i=(a);i<(b);++i) using namespace std; typedef long long LG; const int MX = 200003; LG T[MX]; int D[MX]; int n, m; void query(int d) { LG leftBorder = 0; LG res = 0; FOR(k,0,n) { LG waiting = leftBorder - T[k] + d; if (0 < waiting) { res += waiting; leftBorder += d; } else { leftBorder = T[k]; } } printf("%lld\n", res); } int main() { scanf("%d%d", &n, &m); FOR(i,0,n) scanf("%lld", T + i); FOR(i,0,m) scanf("%d", D + i); FOR(i,0,m) { query(D[i]); } return 0; } |