#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=1e6;
const double PI=acos(-1);
ll pw(ll x, ll p, ll m=mod){
ll ret=1;
while (p>0){
if (p&1){
ret*=x;
ret%=m;
}
x*=x;
x%=m;
p>>=1;
}
return ret;
}
ll inv(ll a, ll m=mod){
return pw(a,m-2);
}
//=======================================================================================
signed main (){
IOS();
int n, q; cin>>n>>q;
vector<int> vc(n), quer(q), ans(n);
vector<pii> cha;
REP(i,n){
cin>>vc[i];
if (i>0) cha.pb({vc[i]-vc[i-1], i});
}
int sm=0, msm=0;
int delt=0;
REP(i,q){
cin>>quer[i];
delt+=quer[i];
sm=min(sm, delt);
msm=max(msm, delt);
}
sm*=(-1);
sort(ALL(cha));
ans[0]+=sm;
ans[n-1]+=msm;
int curl=0, curr=0;
delt=0;
int ptr=0;
REP(i,q){
delt+=quer[i];
if (delt>0) curl=max(curl, delt);
else curr=max(curr, abs(delt));
while(ptr<n-1&&cha[ptr].f<=curl+curr){
int l=curl, r=curr;
if (delt>0){
l-=(curl+curr-cha[ptr].f);
}
else r-=(curl+curr-cha[ptr].f);
ans[cha[ptr].s]+=r;
ans[cha[ptr].s-1]+=l;
ptr++;
}
}
while(ptr<n-1){
ans[cha[ptr].s]+=curr;
ans[cha[ptr].s-1]+=curl;
ptr++;
}
REP(i,n){
cout<<ans[i]<<' ';
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
26 ms |
3908 KB |
Output is correct |
21 |
Correct |
26 ms |
3784 KB |
Output is correct |
22 |
Correct |
27 ms |
3552 KB |
Output is correct |
23 |
Correct |
21 ms |
3492 KB |
Output is correct |
24 |
Correct |
26 ms |
4424 KB |
Output is correct |
25 |
Correct |
86 ms |
13492 KB |
Output is correct |
26 |
Correct |
98 ms |
13472 KB |
Output is correct |
27 |
Correct |
86 ms |
13104 KB |
Output is correct |
28 |
Correct |
83 ms |
13260 KB |
Output is correct |
29 |
Correct |
97 ms |
12868 KB |
Output is correct |
30 |
Correct |
78 ms |
12140 KB |
Output is correct |
31 |
Correct |
70 ms |
11544 KB |
Output is correct |
32 |
Correct |
87 ms |
11736 KB |
Output is correct |
33 |
Correct |
10 ms |
1704 KB |
Output is correct |
34 |
Correct |
80 ms |
13876 KB |
Output is correct |
35 |
Correct |
80 ms |
13248 KB |
Output is correct |
36 |
Correct |
97 ms |
13524 KB |
Output is correct |
37 |
Correct |
77 ms |
13328 KB |
Output is correct |
38 |
Correct |
84 ms |
13212 KB |
Output is correct |
39 |
Correct |
88 ms |
13272 KB |
Output is correct |
40 |
Correct |
88 ms |
13376 KB |
Output is correct |
41 |
Correct |
36 ms |
4544 KB |
Output is correct |
42 |
Correct |
71 ms |
11776 KB |
Output is correct |
43 |
Correct |
77 ms |
15116 KB |
Output is correct |
44 |
Correct |
30 ms |
4416 KB |
Output is correct |
45 |
Correct |
90 ms |
13236 KB |
Output is correct |
46 |
Correct |
83 ms |
15212 KB |
Output is correct |
47 |
Correct |
86 ms |
15372 KB |
Output is correct |
48 |
Correct |
87 ms |
15460 KB |
Output is correct |