// brute force :/
#include <cstdio>
#include <vector>
#define LL long long
LL max(LL a, LL b) {
return a > b ? a : b;
}
using namespace std;
int main() {
LL a,d,n,m;
scanf("%lld %lld", &n, &m);
vector<LL> zs;
while(n--) {
scanf("%lld", &a);
zs.push_back(a);
}
while(m--) {
scanf("%lld", &d);
LL sum = 0;
LL curr = 0;
for (auto it = zs.begin(); it != zs.end(); it++) {
sum += max(0, curr + d - *it);
curr = max(*it, curr + d);
}
printf("%lld\n", sum);
}
}
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 | // brute force :/ #include <cstdio> #include <vector> #define LL long long LL max(LL a, LL b) { return a > b ? a : b; } using namespace std; int main() { LL a,d,n,m; scanf("%lld %lld", &n, &m); vector<LL> zs; while(n--) { scanf("%lld", &a); zs.push_back(a); } while(m--) { scanf("%lld", &d); LL sum = 0; LL curr = 0; for (auto it = zs.begin(); it != zs.end(); it++) { sum += max(0, curr + d - *it); curr = max(*it, curr + d); } printf("%lld\n", sum); } } |
English