#include"bits/stdtr1c++.h"
using namespace std;
long long a,b,c,temp;
vector<long long > k;
long long wynik()
{
long long odp=0;
temp=0;
for(int i=0;i<a;i++)
{
temp=max(k[i],temp+c);
odp+=temp-k[i];
}
return odp;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>a>>b;
k.resize(a);
for(int i=0;i<a;i++)
cin>>k[i];
for(int i=0;i<b;i++)
{
cin>>c;
cout<<wynik()<<'\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 29 30 | #include"bits/stdtr1c++.h" using namespace std; long long a,b,c,temp; vector<long long > k; long long wynik() { long long odp=0; temp=0; for(int i=0;i<a;i++) { temp=max(k[i],temp+c); odp+=temp-k[i]; } return odp; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin>>a>>b; k.resize(a); for(int i=0;i<a;i++) cin>>k[i]; for(int i=0;i<b;i++) { cin>>c; cout<<wynik()<<'\n'; } return 0; } |
English