#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,q;
pll b[maxN+1];
ll x[maxN+1],a[maxN+1],w[maxN+1],l[maxN+1],r[maxN+1];
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
for(int i=1;i<=q;i++)
{
cin>>w[i];
}
ll val=0;
for(int j=1;j<=q;j++)
{
val+=w[j];
for(int i=1;i<=n;i++)
{
l[i]=max(l[i],val);
r[i]=max(r[i],-val);
}
//cout<<j<<'\n';
for(int i=1;i<n;i++)
{
ll tmp=x[i+1]-x[i];
//cout<<i<<" "<<tmp<<" "<<l[i]<<" "<<r[i+1]<<'\n';
if(l[i]+r[i+1]<=tmp)
{
b[i].fi=l[i];
b[i].se=r[i+1];
}
else
{
ll pre_l=b[i].fi,pre_r=b[i].se;
ll cur=tmp-pre_l-pre_r;
if(val>0)
{
b[i].fi+=cur;
}
else b[i].se+=cur;
}
}
}
//cout<<b[1].fi<<'\n';
for(int i=1;i<=n;i++)
{
if(i<n)
{
a[i]+=b[i].fi;
a[i+1]+=b[i].se;
}
if(i==1)
{
a[i]+=r[i];
}
if(i==n)
{
a[i]+=l[i];
}
cout<<a[i]<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
9 ms |
6700 KB |
Output is correct |
5 |
Correct |
9 ms |
6492 KB |
Output is correct |
6 |
Correct |
9 ms |
6668 KB |
Output is correct |
7 |
Correct |
12 ms |
6492 KB |
Output is correct |
8 |
Correct |
9 ms |
6492 KB |
Output is correct |
9 |
Correct |
10 ms |
6488 KB |
Output is correct |
10 |
Correct |
9 ms |
6492 KB |
Output is correct |
11 |
Correct |
8 ms |
6688 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
11 ms |
6492 KB |
Output is correct |
16 |
Correct |
9 ms |
6700 KB |
Output is correct |
17 |
Correct |
9 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
8 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
9 ms |
6700 KB |
Output is correct |
5 |
Correct |
9 ms |
6492 KB |
Output is correct |
6 |
Correct |
9 ms |
6668 KB |
Output is correct |
7 |
Correct |
12 ms |
6492 KB |
Output is correct |
8 |
Correct |
9 ms |
6492 KB |
Output is correct |
9 |
Correct |
10 ms |
6488 KB |
Output is correct |
10 |
Correct |
9 ms |
6492 KB |
Output is correct |
11 |
Correct |
8 ms |
6688 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
11 ms |
6492 KB |
Output is correct |
16 |
Correct |
9 ms |
6700 KB |
Output is correct |
17 |
Correct |
9 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
8 ms |
6492 KB |
Output is correct |
20 |
Correct |
21 ms |
8644 KB |
Output is correct |
21 |
Correct |
22 ms |
8540 KB |
Output is correct |
22 |
Correct |
96 ms |
8164 KB |
Output is correct |
23 |
Correct |
745 ms |
8020 KB |
Output is correct |
24 |
Execution timed out |
2549 ms |
8400 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |