#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,m;
cin >> n >> m;
vector<long long> tab(n);
for(int i=0;i<n;i++)
cin >> tab[i];
sort(tab.begin(),tab.end());
for(int i=0;i<m;i++){
long long k;
long long res = 0;
long long time = 0;
cin >> k;
for(int j=0;j<n;j++){
if(tab[j] - k < time){
res += time - tab[j] + k;
time = time + k;
}
else
time = tab[j];
}
cout<<res<<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 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector<long long> tab(n); for(int i=0;i<n;i++) cin >> tab[i]; sort(tab.begin(),tab.end()); for(int i=0;i<m;i++){ long long k; long long res = 0; long long time = 0; cin >> k; for(int j=0;j<n;j++){ if(tab[j] - k < time){ res += time - tab[j] + k; time = time + k; } else time = tab[j]; } cout<<res<<endl; } return 0; } |
English