#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int ans[N];
int sm[N*4];
pair< int,int > a[N];
int b[N];
void build(int l,int r,int now)
{
if(l==r) {sm[now] = max(a[l+1].first-b[l],0);return;}
int mid = (l+r) >> 1;
build(l,mid,now<<1),build(mid+1,r,now<<1|1);
sm[now] = max(sm[now<<1],sm[now<<1|1]);;
}
void upd(int l,int r,int idx,int now)
{
if(l>idx||r<idx) return ;
if(l==r) {sm[now] = max(0,a[l].first-b[l]);return ;}
int mid = (l+r) >> 1;
upd(l,mid,idx,now<<1),upd(mid+1,r,idx,now<<1|1);
sm[now] = max(sm[now<<1],sm[now<<1|1]);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n+1;i++) scanf("%d",&a[i].first),a[i].second = i;
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
sort(a+1,a+n+2),sort(b+1,b+n+1);
build(1,n,1);
ans[a[1].second] = sm[1];
for(int i=1;i<=n;i++)
{
upd(1,n,i,1);
ans[a[i+1].second] = sm[1];
}
for(int i=1;i<=n+1;i++) printf("%d ",ans[i]);
return 0;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
ho_t1.cpp:27:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n+1;i++) scanf("%d",&a[i].first),a[i].second = i;
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t1.cpp:28:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
6 ms |
384 KB |
Output is correct |
23 |
Correct |
7 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
7 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
6 ms |
384 KB |
Output is correct |
23 |
Correct |
7 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
7 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
6 ms |
384 KB |
Output is correct |
33 |
Correct |
157 ms |
10616 KB |
Output is correct |
34 |
Correct |
163 ms |
10872 KB |
Output is correct |
35 |
Correct |
155 ms |
10616 KB |
Output is correct |
36 |
Correct |
159 ms |
11128 KB |
Output is correct |
37 |
Correct |
162 ms |
11384 KB |
Output is correct |
38 |
Correct |
168 ms |
11232 KB |
Output is correct |
39 |
Correct |
162 ms |
10360 KB |
Output is correct |
40 |
Correct |
157 ms |
10232 KB |
Output is correct |
41 |
Correct |
166 ms |
10616 KB |
Output is correct |
42 |
Correct |
162 ms |
10360 KB |
Output is correct |
43 |
Correct |
156 ms |
10232 KB |
Output is correct |
44 |
Correct |
156 ms |
9976 KB |
Output is correct |
45 |
Correct |
164 ms |
9976 KB |
Output is correct |
46 |
Correct |
162 ms |
9976 KB |
Output is correct |
47 |
Correct |
146 ms |
10104 KB |
Output is correct |
48 |
Correct |
145 ms |
9940 KB |
Output is correct |
49 |
Correct |
160 ms |
10616 KB |
Output is correct |
50 |
Correct |
162 ms |
10488 KB |
Output is correct |
51 |
Correct |
161 ms |
10492 KB |
Output is correct |
52 |
Correct |
166 ms |
10488 KB |
Output is correct |
53 |
Correct |
166 ms |
10488 KB |
Output is correct |