# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=1e6+5;
long long n,q,qq[N],a[N],prmx[N],pr[N],prmn[N],x1,x2,le,ri,anss,rii[N],lef[N],mid,x;
int main() {
cin>>n>>q;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=q; i++) {
cin>>qq[i];
pr[i]=pr[i-1]+qq[i];
prmx[i]=max(prmx[i-1],pr[i]);
prmn[i]=min(prmn[i-1],pr[i]);
}
for(int i=2; i<=n; i++) {
x1=a[i-1];
x2=a[i];
le=1;
ri=q;
while (le<=ri) {
anss=0;
mid=(le+ri)/2;
if (x1+prmx[mid]<=x2+prmn[mid]) {
anss=mid;
//m1=x1+prmx[mid];
//m2=x2+prmn[mid];
le=mid+1;
}
else ri=mid-1;
}
if (prmn[anss+1]<prmn[anss]) {
lef[i]=x1+prmx[anss];
} else {
lef[i]=x2+prmn[anss];
}
//if(i==4) cout<<anss<<endl<<endl;
lef[i]=min(a[i],lef[i]);
}
for (int i=1; i<n; i++) {
x1=a[i];
x2=a[i+1];
le=1;
ri=q;
anss=0;
while (le<=ri) {
mid=(le+ri)/2;
if (x1+prmx[mid]<=x2+prmn[mid]) {
anss=mid;
//rii[i]=x2+prmn[mid];
le=mid+1;
}
else ri=mid-1;
}
if (prmx[anss+1]>prmx[anss]) {
rii[i]=x2+prmn[anss];
}
else rii[i]=x1+prmx[anss];
rii[i]=max(a[i],rii[i]);
}
lef[1]=min(a[1], a[1]+prmn[q]);
rii[n]=max(a[n], a[n]+prmx[q]);
for (int i=1; i<=n; i++) {
// cout<<rii[i]<<" "<<lef[i]<<endl;
cout<<rii[i]-lef[i]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |