#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int n ,m;
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
vector<long long> czasy;
czasy.resize(n);
for(int i = 0; i < n ; i++)
{
cin >> czasy[i];
}
for(int i = 0; i < m; i++)
{
long long b;
cin >> b;
long long l = 0;
int id = 0;
long long wynik = 0;
while(id<n)
{
wynik+= max((long long)0, l+b-czasy[id]);
l = max(l+b, czasy[id]);
id++;
}
cout << wynik << 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 | #include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; int main() { int n ,m; cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; vector<long long> czasy; czasy.resize(n); for(int i = 0; i < n ; i++) { cin >> czasy[i]; } for(int i = 0; i < m; i++) { long long b; cin >> b; long long l = 0; int id = 0; long long wynik = 0; while(id<n) { wynik+= max((long long)0, l+b-czasy[id]); l = max(l+b, czasy[id]); id++; } cout << wynik << endl; } return 0; } |
English