#include<bits/stdc++.h>
using namespace std;
long long tab[1000005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a,b,c;
cin>>a>>b;
for(int x=0;x<a;x++)
cin>>tab[x];
long long pom,licz;
for(int x=0;x<b;x++)
{
cin>>c;
pom=0; licz=0;
for(int y=0;y<a;y++)
{
pom+=c;
if(tab[y]>=pom)
pom=tab[y];
else
licz+=(pom-tab[y]);
}
cout<<licz<<'\n';
}
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 | #include<bits/stdc++.h> using namespace std; long long tab[1000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,b,c; cin>>a>>b; for(int x=0;x<a;x++) cin>>tab[x]; long long pom,licz; for(int x=0;x<b;x++) { cin>>c; pom=0; licz=0; for(int y=0;y<a;y++) { pom+=c; if(tab[y]>=pom) pom=tab[y]; else licz+=(pom-tab[y]); } cout<<licz<<'\n'; } return 0; } |
English