#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long b[2000005],pre[2000005],suf[2000005],ans[2000005],plc[2000005];
pair <long long, long long> a[2000005];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin>>n;
vector < pair <long long, long long > > c;
for(int i=1;i<=n+1;i++){
cin>>a[i].first;
a[i].second=i;
}
for(int i=1;i<=n;i++)
cin>>b[i];
sort(b+1,b+n+1);
sort(a+1,a+n+2);
for(int i=1;i<=n+1;i++)
{
plc[a[i].second]=i;
}
for(int i=1;i<=n;i++)
{
pre[i]=max(pre[i-1],a[i].first-b[i]);
//cout<<pre[i]<<" ";
}
//cout<<"\n";
for(int i=n;i>=1;i--)
{
suf[i]=max(suf[i+1],a[i+1].first-b[i]);
//cout<<suf[i]<<" ";
}
//cout<<"\n";
for(int i=1;i<=n+1;i++)
{
ans[a[i].second]=max(pre[plc[a[i].second]-1],suf[plc[a[i].second]]);
//cout<<pre[a[i].first-1]<<" "<<suf[a[i].first]<<" "<<a[i].first<<"f\n";
}
for(int i=1;i<=n+1;i++)
cout<<ans[i]<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
556 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
556 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
90 ms |
12320 KB |
Output is correct |
34 |
Correct |
89 ms |
12728 KB |
Output is correct |
35 |
Correct |
92 ms |
12364 KB |
Output is correct |
36 |
Correct |
89 ms |
12796 KB |
Output is correct |
37 |
Correct |
92 ms |
13200 KB |
Output is correct |
38 |
Correct |
87 ms |
13016 KB |
Output is correct |
39 |
Correct |
84 ms |
12056 KB |
Output is correct |
40 |
Correct |
81 ms |
12108 KB |
Output is correct |
41 |
Correct |
85 ms |
12120 KB |
Output is correct |
42 |
Correct |
83 ms |
12172 KB |
Output is correct |
43 |
Correct |
80 ms |
12044 KB |
Output is correct |
44 |
Correct |
80 ms |
11580 KB |
Output is correct |
45 |
Correct |
83 ms |
11720 KB |
Output is correct |
46 |
Correct |
84 ms |
11580 KB |
Output is correct |
47 |
Correct |
83 ms |
11744 KB |
Output is correct |
48 |
Correct |
79 ms |
11764 KB |
Output is correct |
49 |
Correct |
87 ms |
12492 KB |
Output is correct |
50 |
Correct |
84 ms |
12448 KB |
Output is correct |
51 |
Correct |
98 ms |
12408 KB |
Output is correct |
52 |
Correct |
86 ms |
12444 KB |
Output is correct |
53 |
Correct |
86 ms |
12476 KB |
Output is correct |