#include <iostream>
using namespace std;
long long T[200001];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int N,M;
int D;
cin>>N>>M;
for(int i = 1;i <= N;i++)
{
cin>>T[i];
}
for(int _ = 0;_ < M;_++)
{
cin>>D;
int Result = 0;
int Time = D;
for(int i = 1; i<= N;i++)
{
if(Time > T[i])Result += Time - T[i];
Time = T[i] + D;
}
cout<<Result<<'\n';
}
}
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 | #include <iostream> using namespace std; long long T[200001]; int main() { ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int N,M; int D; cin>>N>>M; for(int i = 1;i <= N;i++) { cin>>T[i]; } for(int _ = 0;_ < M;_++) { cin>>D; int Result = 0; int Time = D; for(int i = 1; i<= N;i++) { if(Time > T[i])Result += Time - T[i]; Time = T[i] + D; } cout<<Result<<'\n'; } } |
English