#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int n, m;
cin>>n>>m;
int tab[n];
for(int x=0;x<n;x++){
cin>>tab[x];
}
while(m--){
long long c;
cin>>c;
long long h=0, l=0;
for(int x=0;x<n;x++){
if(tab[x]-l<c){
h+=c+l-tab[x];
l+=c;
} else {
l=tab[x];
}
}
cout<<h<<endl;
}
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 | #include <iostream> using namespace std; int main(){ ios::sync_with_stdio(false); int n, m; cin>>n>>m; int tab[n]; for(int x=0;x<n;x++){ cin>>tab[x]; } while(m--){ long long c; cin>>c; long long h=0, l=0; for(int x=0;x<n;x++){ if(tab[x]-l<c){ h+=c+l-tab[x]; l+=c; } else { l=tab[x]; } } cout<<h<<endl; } return 0; } |
English