#include <iostream>
#include <vector>
using namespace std;
int n,m;
long long minroz=100000000000000;
long long x;
vector<long long>t;
int policz(int leap){
int teraz=0;
int delay=0;
if(leap>minroz){
for(int i=0; i<n; i++){
if(teraz+leap<=t[i]){
teraz=t[i];
}else{
teraz+=leap;
delay+=(teraz-t[i]);
}
}
}
return delay;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
cin >> x;
minroz=min(minroz,x);
t.push_back(x);
for(int i=1; i<n; i++){
cin >> x;
t.push_back(x);
minroz=min(minroz,x-t[i-1]);
}
for(int i=0; i<m; i++){
cin >> x;
cout << policz(x)<<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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> #include <vector> using namespace std; int n,m; long long minroz=100000000000000; long long x; vector<long long>t; int policz(int leap){ int teraz=0; int delay=0; if(leap>minroz){ for(int i=0; i<n; i++){ if(teraz+leap<=t[i]){ teraz=t[i]; }else{ teraz+=leap; delay+=(teraz-t[i]); } } } return delay; } int main(){ ios_base::sync_with_stdio(0); cin >> n >> m; cin >> x; minroz=min(minroz,x); t.push_back(x); for(int i=1; i<n; i++){ cin >> x; t.push_back(x); minroz=min(minroz,x-t[i-1]); } for(int i=0; i<m; i++){ cin >> x; cout << policz(x)<<endl;; } return 0; } |
English