#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
if(x>y)
{
x=y;
return 1;
}
return 0;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef thuc
freopen("input.INP","r",stdin);
freopen("output.OUT","w",stdout);
#endif
}
const ll N=2e5+10,M=998244353;
ll a[N],n,ans[N];
int main()
{
online();
vector<pll> vt;
ll q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i>1) vt.emplace_back(a[i]-a[i-1],i);
}
vt.emplace_back(1e14,1);
vt.emplace_back(1e14,n+1);
sort(vt.begin(),vt.end(),greater<pll>());
// for(auto [x,y]:vt) cout<<x<<' '<<y<<'\n';
ll mx=0,mn=0,cr=0;
while(q--)
{
ll x;
cin>>x;
cr+=x;
if(minimize(mn,cr))
{
while(vt.back().fi<=(mx-mn))
{
ll k=vt.back().se;
ans[k-1]+=mx;
ll z=vt.back().fi-mx;
ans[k]+=z;
vt.pop_back();
}
}
if(maximize(mx,cr))
{
while(vt.back().fi<=(mx-mn))
{
ll k=vt.back().se;
ans[k]-=mn;
ll z=vt.back().fi+mn;
ans[k-1]+=z;
vt.pop_back();
}
}
}
while(vt.size())
{
ll k=vt.back().se;
ans[k]-=mn;
ans[k-1]+=mx;
vt.pop_back();
}
for(int i=1;i<=n;i++)
{
cout<<ans[i]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
404 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
404 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
18 ms |
2388 KB |
Output is correct |
21 |
Correct |
18 ms |
2228 KB |
Output is correct |
22 |
Correct |
19 ms |
1996 KB |
Output is correct |
23 |
Correct |
16 ms |
1936 KB |
Output is correct |
24 |
Correct |
20 ms |
2888 KB |
Output is correct |
25 |
Correct |
68 ms |
12052 KB |
Output is correct |
26 |
Correct |
62 ms |
11960 KB |
Output is correct |
27 |
Correct |
65 ms |
11536 KB |
Output is correct |
28 |
Correct |
63 ms |
11744 KB |
Output is correct |
29 |
Correct |
62 ms |
11276 KB |
Output is correct |
30 |
Correct |
58 ms |
10640 KB |
Output is correct |
31 |
Correct |
58 ms |
10000 KB |
Output is correct |
32 |
Correct |
43 ms |
10164 KB |
Output is correct |
33 |
Correct |
7 ms |
1620 KB |
Output is correct |
34 |
Correct |
61 ms |
12376 KB |
Output is correct |
35 |
Correct |
59 ms |
11748 KB |
Output is correct |
36 |
Correct |
63 ms |
11956 KB |
Output is correct |
37 |
Correct |
63 ms |
11732 KB |
Output is correct |
38 |
Correct |
64 ms |
11572 KB |
Output is correct |
39 |
Correct |
64 ms |
11704 KB |
Output is correct |
40 |
Correct |
62 ms |
11776 KB |
Output is correct |
41 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |