#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,b[200005],sol[200005],one[200005],two[200005];
struct date
{
ll val,poz;
} a[200005];
bool comp(date a, date b)
{
return a.val<b.val;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n+1;i++)
{
cin>>a[i].val;
a[i].poz=i;
}
for(int i=1;i<=n;i++)
cin>>b[i];
sort(b+1,b+n+1);
sort(a+1,a+n+2,comp);
for(int i=1;i<=n;i++)
{
one[i]=max(0LL,a[i].val-b[i]);
two[i]=max(0LL,a[i+1].val-b[i]);
}
for(int i=1;i<=n;i++)
one[i]=max(one[i],one[i-1]);
for(int i=n;i>=1;i--)
two[i]=max(two[i],two[i+1]);
for(int i=1;i<=n+1;i++)
{
ll val=a[i].val,poz=a[i].poz;
ll ans=0;
ans=max(ans,one[i-1]);
ans=max(ans,two[i]);
sol[poz]=ans;
}
for(int i=1;i<=n+1;i++)
cout<<sol[i]<<' ';
return 0;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:39:12: warning: unused variable 'val' [-Wunused-variable]
39 | ll val=a[i].val,poz=a[i].poz;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
400 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
400 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
90 ms |
10672 KB |
Output is correct |
34 |
Correct |
90 ms |
14968 KB |
Output is correct |
35 |
Correct |
90 ms |
14540 KB |
Output is correct |
36 |
Correct |
88 ms |
15012 KB |
Output is correct |
37 |
Correct |
90 ms |
15548 KB |
Output is correct |
38 |
Correct |
94 ms |
15464 KB |
Output is correct |
39 |
Correct |
88 ms |
14312 KB |
Output is correct |
40 |
Correct |
91 ms |
14240 KB |
Output is correct |
41 |
Correct |
90 ms |
14540 KB |
Output is correct |
42 |
Correct |
89 ms |
14384 KB |
Output is correct |
43 |
Correct |
89 ms |
14232 KB |
Output is correct |
44 |
Correct |
85 ms |
13820 KB |
Output is correct |
45 |
Correct |
93 ms |
13928 KB |
Output is correct |
46 |
Correct |
86 ms |
13752 KB |
Output is correct |
47 |
Correct |
73 ms |
14080 KB |
Output is correct |
48 |
Correct |
75 ms |
14124 KB |
Output is correct |
49 |
Correct |
93 ms |
14740 KB |
Output is correct |
50 |
Correct |
91 ms |
14668 KB |
Output is correct |
51 |
Correct |
92 ms |
14636 KB |
Output is correct |
52 |
Correct |
97 ms |
14640 KB |
Output is correct |
53 |
Correct |
92 ms |
14748 KB |
Output is correct |