#include<bits/stdc++.h>
using namespace std;
const int N=200002;
int n,m;
long long suma,t[N],x,d;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>t[i];
for(int i=0;i<m;++i){
cin>>d;
suma=0; x=0;
for(int j=1;j<=n;++j){
x+=d-t[j]+t[j-1];
if(x<0) x=0;
suma+=x;
}
cout<<suma<<'\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 | #include<bits/stdc++.h> using namespace std; const int N=200002; int n,m; long long suma,t[N],x,d; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(int i=1;i<=n;++i) cin>>t[i]; for(int i=0;i<m;++i){ cin>>d; suma=0; x=0; for(int j=1;j<=n;++j){ x+=d-t[j]+t[j-1]; if(x<0) x=0; suma+=x; } cout<<suma<<'\n'; } return 0; } |
English