#include<bits/stdc++.h>
using namespace std;
const int N = 200003;
long long t[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++) scanf("%lld", &t[i]);
while(m--) {
int a;
scanf("%d", &a);
long long czas = 0;
long long skoncze = t[0];
if(t[0]<a) {
skoncze = a;
czas = a-t[0];
}
for(int i = 1; i < n; i++) {
if(t[i]-skoncze>=a)
skoncze = t[i];
else {
czas += skoncze+a-t[i];
skoncze += a;
}
}
printf("%lld\n", czas);
}
}
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 | #include<bits/stdc++.h> using namespace std; const int N = 200003; long long t[N]; int main() { int n, m; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) scanf("%lld", &t[i]); while(m--) { int a; scanf("%d", &a); long long czas = 0; long long skoncze = t[0]; if(t[0]<a) { skoncze = a; czas = a-t[0]; } for(int i = 1; i < n; i++) { if(t[i]-skoncze>=a) skoncze = t[i]; else { czas += skoncze+a-t[i]; skoncze += a; } } printf("%lld\n", czas); } } |
English