#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i,a,b) for(ll i=a;i<=b;++i)
#define ff(i,a,b) for(ll i=a;i>=b;--i)
#define fi first
#define se second
#define endl '\n'
#define task "task"
#define task "task"
#define prll pair<ll,ll>
#define pb push_back
#define ld long double
const ll MIN=-1e18,MAX=1e18,MOD=1e9+7;
prll b[200005];
ll c[200005],mx1[200005],mx2[200005],h1[200005],h2[200005],ans[200005];
int main()
{
// #ifndef ONLINE_JUDGE
// freopen (task".inp", "r", stdin);
// freopen (task".out", "w", stdout);
// #endif
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll a;
cin>>a;
fo(i,1,a+1)
{
cin>>b[i].fi;
b[i].se=i;
}
fo(i,1,a)
{
cin>>c[i];
}
sort(b+1,b+2+a);
sort(c+1,c+1+a);
fo(i,1,a)
{
h1[i]=max((ll)0,b[i].fi-c[i]);
h2[i]=max((ll)0,b[i+1].fi-c[i]);
}
fo(i,1,a)
{
mx1[i]=max(h1[i],mx1[i-1]);
}
ff(i,a,1)
{
mx2[i]=max(h2[i],mx2[i+1]);
}
fo(i,1,a+1)
{
ans[b[i].se]=max(mx1[i-1],mx2[i]);
}
fo(i,1,a+1) cout<<ans[i]<<" ";
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
324 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
472 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
520 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
508 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 |
472 KB |
Output is correct |
32 |
Correct |
1 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
324 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
472 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
520 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
508 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 |
472 KB |
Output is correct |
32 |
Correct |
1 ms |
476 KB |
Output is correct |
33 |
Correct |
82 ms |
17372 KB |
Output is correct |
34 |
Correct |
86 ms |
18124 KB |
Output is correct |
35 |
Correct |
84 ms |
17556 KB |
Output is correct |
36 |
Correct |
84 ms |
18060 KB |
Output is correct |
37 |
Correct |
94 ms |
18628 KB |
Output is correct |
38 |
Correct |
87 ms |
18380 KB |
Output is correct |
39 |
Correct |
85 ms |
17356 KB |
Output is correct |
40 |
Correct |
90 ms |
17340 KB |
Output is correct |
41 |
Correct |
83 ms |
17500 KB |
Output is correct |
42 |
Correct |
82 ms |
17468 KB |
Output is correct |
43 |
Correct |
94 ms |
17276 KB |
Output is correct |
44 |
Correct |
81 ms |
16872 KB |
Output is correct |
45 |
Correct |
84 ms |
16912 KB |
Output is correct |
46 |
Correct |
83 ms |
16748 KB |
Output is correct |
47 |
Correct |
79 ms |
17224 KB |
Output is correct |
48 |
Correct |
80 ms |
17244 KB |
Output is correct |
49 |
Correct |
94 ms |
17788 KB |
Output is correct |
50 |
Correct |
87 ms |
17792 KB |
Output is correct |
51 |
Correct |
91 ms |
17944 KB |
Output is correct |
52 |
Correct |
83 ms |
17784 KB |
Output is correct |
53 |
Correct |
84 ms |
17868 KB |
Output is correct |