#include <cstdio> int main(void){ long long n, m, i, tmp, piec, *p; long long *k; long long zapKoniec, suma; scanf("%lld %lld", &n, &m); k = new long long [n]; p = new long long [m]; for(i = 0; i < n; i++) scanf("%lld", &k[i]); for(i = 0; i < m; i++) scanf("%lld", &p[i]); for(piec = 0; piec < m; piec++){ suma = zapKoniec = 0; for(i = 0; i < n; i++){ tmp = k[i] - zapKoniec - p[piec]; if(tmp < 0){ suma -= tmp; zapKoniec += p[piec]; } else zapKoniec = k[i]; } printf("%lld\n", suma); } delete k; delete p; 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 | #include <cstdio> int main(void){ long long n, m, i, tmp, piec, *p; long long *k; long long zapKoniec, suma; scanf("%lld %lld", &n, &m); k = new long long [n]; p = new long long [m]; for(i = 0; i < n; i++) scanf("%lld", &k[i]); for(i = 0; i < m; i++) scanf("%lld", &p[i]); for(piec = 0; piec < m; piec++){ suma = zapKoniec = 0; for(i = 0; i < n; i++){ tmp = k[i] - zapKoniec - p[piec]; if(tmp < 0){ suma -= tmp; zapKoniec += p[piec]; } else zapKoniec = k[i]; } printf("%lld\n", suma); } delete k; delete p; return 0; } |