#include<iostream>
using namespace std;
int n,m,w,i,j,s,T;
int main ()
{
ios_base::sync_with_stdio (0);
cin>>n>>m;
int t[n+1],d[m];
for(i; i<n; i++)
{
cin>>t[i];
}
t[i+1]=9999999999;
for(i=0; i<m; i++)
{
cin>>d[i];
j=0;
w=0;
s=d[i];
T=d[i];
if(t[0]-T<0)
{
w+=T-t[0];
}
while(j<n)
{
if(t[j+1]<=w)
{
w+=d[i];
}
else
{
if(t[j+1]==t[j])
{
w+=d[i];
}
else
{
if(t[j+1]-T<d[i])
{
w+=d[i]-(t[j+1]-T);
}
}
}
T=t[j+1];
j++;
}
cout<<w<<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 45 46 47 48 49 50 51 | #include<iostream> using namespace std; int n,m,w,i,j,s,T; int main () { ios_base::sync_with_stdio (0); cin>>n>>m; int t[n+1],d[m]; for(i; i<n; i++) { cin>>t[i]; } t[i+1]=9999999999; for(i=0; i<m; i++) { cin>>d[i]; j=0; w=0; s=d[i]; T=d[i]; if(t[0]-T<0) { w+=T-t[0]; } while(j<n) { if(t[j+1]<=w) { w+=d[i]; } else { if(t[j+1]==t[j]) { w+=d[i]; } else { if(t[j+1]-T<d[i]) { w+=d[i]-(t[j+1]-T); } } } T=t[j+1]; j++; } cout<<w<<endl; } return 0; } |
English