#include <iostream>
#include <climits>
using namespace std;
const int nmax=2e5;
long long 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];
}
long long int dep=0;
for (int i=1;i<=nrq;i++)
{
long long 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++)
{
long long 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] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |