#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pii pair<int,int>
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define inf 1000'000'000'000'000'000
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ",_do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ... S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=200005;
int n,m,a[maxn],b[maxn],maxx[maxn],minn[maxn],res[maxn];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
rep(n) cin >> a[i];
rep(m) cin >> b[i];
maxx[0]=minn[0]=0;
int cur=0;
rep(m){
cur+=b[i];
maxx[i+1]=max(maxx[i],cur);
minn[i+1]=min(minn[i],cur);
bug(i+1,maxx[i+1],minn[i+1]);
}
res[n-1]+=maxx[m];
res[0]-=minn[m];
rep(n-1){
if(maxx[m]-minn[m]<=a[i+1]-a[i]){
res[i]+=maxx[m];
res[i+1]-=minn[m];
continue;
}
int l=0,r=m;
while(l<r){
int mid=l+r+1>>1;
if(maxx[mid]-minn[mid]<=a[i+1]-a[i]) l=mid;
else r=mid-1;
}
bug(l);
if(b[l]>0){
res[i+1]-=minn[l];
res[i]+=a[i+1]-a[i]+minn[l];
}
else{
res[i]+=maxx[l];
res[i+1]+=a[i+1]-a[i]-maxx[l];
}
}
rep(n) cout << res[i] << endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:21:18: warning: statement has no effect [-Wunused-value]
21 | #define bug(...) 49
| ^~
Main.cpp:39:9: note: in expansion of macro 'bug'
39 | bug(i+1,maxx[i+1],minn[i+1]);
| ^~~
Main.cpp:51:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int mid=l+r+1>>1;
| ~~~^~
Main.cpp:21:18: warning: statement has no effect [-Wunused-value]
21 | #define bug(...) 49
| ^~
Main.cpp:55:9: note: in expansion of macro 'bug'
55 | bug(l);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
368 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
368 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
26 ms |
7044 KB |
Output is correct |
21 |
Correct |
24 ms |
6924 KB |
Output is correct |
22 |
Correct |
24 ms |
6712 KB |
Output is correct |
23 |
Correct |
24 ms |
6560 KB |
Output is correct |
24 |
Correct |
51 ms |
7068 KB |
Output is correct |
25 |
Correct |
320 ms |
12840 KB |
Output is correct |
26 |
Correct |
312 ms |
12740 KB |
Output is correct |
27 |
Correct |
307 ms |
12548 KB |
Output is correct |
28 |
Correct |
311 ms |
12484 KB |
Output is correct |
29 |
Correct |
310 ms |
12300 KB |
Output is correct |
30 |
Correct |
305 ms |
11944 KB |
Output is correct |
31 |
Correct |
273 ms |
11460 KB |
Output is correct |
32 |
Correct |
276 ms |
11788 KB |
Output is correct |
33 |
Correct |
30 ms |
1576 KB |
Output is correct |
34 |
Correct |
311 ms |
12728 KB |
Output is correct |
35 |
Correct |
310 ms |
12612 KB |
Output is correct |
36 |
Correct |
310 ms |
12704 KB |
Output is correct |
37 |
Correct |
307 ms |
12608 KB |
Output is correct |
38 |
Correct |
302 ms |
12436 KB |
Output is correct |
39 |
Correct |
318 ms |
12472 KB |
Output is correct |
40 |
Correct |
282 ms |
12476 KB |
Output is correct |
41 |
Correct |
27 ms |
7620 KB |
Output is correct |
42 |
Correct |
260 ms |
11472 KB |
Output is correct |
43 |
Correct |
294 ms |
12656 KB |
Output is correct |
44 |
Correct |
27 ms |
7576 KB |
Output is correct |
45 |
Correct |
270 ms |
12440 KB |
Output is correct |
46 |
Correct |
296 ms |
12740 KB |
Output is correct |
47 |
Correct |
294 ms |
12740 KB |
Output is correct |
48 |
Correct |
297 ms |
12852 KB |
Output is correct |