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 <iostream>
#include <climits>
using namespace std;
const int nmax=2e5;
int n, nrq, mx[nmax+5], mn[nmax+5], poz[nmax+5], mn_dep=INT_MIN, mx_dep=INT_MIN, rez[nmax+5];
int main()
{
cin >> n >> nrq;
for (int i=1;i<=n;i++)
{
cin >> poz[i];
}
int dep=0;
for (int i=1;i<=nrq;i++)
{
int val;
cin >> val;
dep+=val;
mn[i]=min (mn[i-1], dep);
mx[i]=max (mx[i-1], dep);
}
rez[1]+=abs (mn[nrq]);
rez[n]+=mx[nrq];
for (int i=2;i<=n;i++)
{
int st=1, dr=nrq, ret=0;
while (st<=dr)
{
int mij = (st+dr) >> 1;
if (poz[i]-poz[i-1]>mx[mij]-mn[mij])
{
ret=mij;
st=mij+1;
}
else dr=mij-1;
}
rez[i-1]+=mx[ret];
if (ret+1<=n && mx[ret+1]>mx[ret])
{
rez[i-1]+=poz[i]-poz[i-1]-(mx[ret]-mn[ret]);
}
else if (ret+1<=n)
{
rez[i]+=poz[i]-poz[i-1]-(mx[ret]-mn[ret]);
}
rez[i]+=abs (mn[ret]);
}
for (int i=1;i<=n;i++)
{
cout << rez[i] << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |