This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int n,q,x,i,st,dr,mid,sol,l;
int v[N],s[N],mn[N],mx[N],k[N],g[N];
int main()
{
cin>>n>>q;
for(i=1;i<=n;++i)
{
cin>>v[i];
}
for(i=1;i<=q;++i)
{
cin>>x;
s[i]=s[i-1]+x;
mn[i]=min(mn[i-1],s[i]);
mx[i]=max(mx[i-1],s[i]);
k[i]=abs(mn[i])+mx[i];
}
for(i=1;i<n;++i)
{
st=1; dr=q;
sol=q;
l=v[i+1]-v[i];
while(st<=dr)
{
mid=(st+dr)>>1;
if(l>k[mid]) st=mid+1;
else {sol=mid; dr=mid-1;}
}
if(k[sol]<l)
{
g[i]+=mx[sol];
g[i+1]+=abs(mn[sol]);
}
else
{
g[i]+=mx[sol-1];
g[i+1]+=abs(mn[sol-1]);
if(mx[sol]>mx[sol-1])
{
g[i]+=l-k[sol-1];
}
else
{
g[i+1]+=l-k[sol-1];
}
}
}
g[1]+=abs(mn[q]);
g[n]+=mx[q];
for(i=1;i<=n;++i)
{
cout<<g[i]<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |