#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
struct st{
ll a,b,c;
friend bool operator < (st a, st b)
{
return a.a<b.a;
}
};
main()
{
ll n,z;
cin>>n>>z;
ll cad[n];
ll v[2][n];
for(int i=0; i<n; i++)
{
cin>>cad[i];
v[0][i]=0;
v[1][i]=0;
}
priority_queue<st> q;
for(int i=0; i<n-1; i++)
{
q.push({-(cad[i+1]-cad[i]),i,i+1});
}
ll i=0;
ll d=0;
ll ia=0;
ll da=0;
while(z--)
{
ll t;
cin>>t;
ia+=t;
da+=t;
ll ac=-min(i,ia)+max(d,da);
while(!q.empty()&&ac>=-q.top().a)
{
st a=q.top();q.pop();
v[1][a.b]+=d;
v[0][a.c]+=i;
if(t<0)
v[0][a.c]-=(-a.a)-d+i;
else
v[1][a.b]+=(-a.a)-d+i;
}
i=min(i,ia);
d=max(d,da);
}
while(!q.empty())
{
st a=q.top();q.pop();
v[1][a.b]+=d;
v[0][a.c]+=i;
}
v[0][0]+=i;
v[1][n-1]+=d;
for(int i=0; i<n; i++)
{
cout<<v[1][i]-v[0][i]<<"\n";
}
}
Compilation message
Main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
432 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
448 KB |
Output is correct |
20 |
Correct |
60 ms |
2388 KB |
Output is correct |
21 |
Correct |
63 ms |
2216 KB |
Output is correct |
22 |
Correct |
53 ms |
2160 KB |
Output is correct |
23 |
Correct |
63 ms |
2128 KB |
Output is correct |
24 |
Correct |
55 ms |
3152 KB |
Output is correct |
25 |
Correct |
162 ms |
15708 KB |
Output is correct |
26 |
Correct |
158 ms |
15564 KB |
Output is correct |
27 |
Correct |
155 ms |
16056 KB |
Output is correct |
28 |
Correct |
158 ms |
15692 KB |
Output is correct |
29 |
Correct |
154 ms |
15468 KB |
Output is correct |
30 |
Correct |
142 ms |
15556 KB |
Output is correct |
31 |
Correct |
127 ms |
14044 KB |
Output is correct |
32 |
Correct |
130 ms |
16204 KB |
Output is correct |
33 |
Correct |
17 ms |
2132 KB |
Output is correct |
34 |
Correct |
172 ms |
15944 KB |
Output is correct |
35 |
Correct |
168 ms |
15812 KB |
Output is correct |
36 |
Correct |
161 ms |
16052 KB |
Output is correct |
37 |
Correct |
160 ms |
15796 KB |
Output is correct |
38 |
Correct |
158 ms |
16032 KB |
Output is correct |
39 |
Correct |
155 ms |
15836 KB |
Output is correct |
40 |
Correct |
146 ms |
15808 KB |
Output is correct |
41 |
Correct |
71 ms |
2900 KB |
Output is correct |
42 |
Correct |
143 ms |
14408 KB |
Output is correct |
43 |
Correct |
178 ms |
17704 KB |
Output is correct |
44 |
Correct |
69 ms |
2972 KB |
Output is correct |
45 |
Correct |
166 ms |
16324 KB |
Output is correct |
46 |
Correct |
176 ms |
16836 KB |
Output is correct |
47 |
Correct |
186 ms |
17724 KB |
Output is correct |
48 |
Correct |
189 ms |
17348 KB |
Output is correct |