#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
vector<pair<int,int>> a(n+2),b(n+1);
for(int i=1;i<=n+1;++i) cin >> a[i].first;
for(int i=1;i<=n;++i) cin >> b[i].first;
for(int i=1;i<=n+1;++i) a[i].second=i;
sort(a.begin()+1,a.end());
sort(b.begin()+1,b.end());
vector<int> Lans(n+5,-1e18),Rans(n+5,-1e18);
for(int i=1;i<=n;++i){
Lans[i]=max(Lans[i-1],max(0LL,a[i].first-b[i].first));
// cout << "Lans" << Lans[i] << '\n';
}
for(int i=n+1;i>=2;--i){
Rans[i]=max(Rans[i+1],max(0LL,a[i].first-b[i-1].first));
// cout << "Rans" << Rans[i] << '\n';
}
vector<int> ans(n+2);
for(int i=1;i<=n+1;++i){
ans[a[i].second]=max(Lans[i-1],Rans[i+1]);
// cout << "a[i].second" << a[i].second << '\n';
}
for(int i=1;i<=n+1;++i)
cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
456 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
456 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
108 ms |
15856 KB |
Output is correct |
34 |
Correct |
113 ms |
16492 KB |
Output is correct |
35 |
Correct |
112 ms |
16068 KB |
Output is correct |
36 |
Correct |
110 ms |
16468 KB |
Output is correct |
37 |
Correct |
113 ms |
17044 KB |
Output is correct |
38 |
Correct |
115 ms |
16836 KB |
Output is correct |
39 |
Correct |
112 ms |
15864 KB |
Output is correct |
40 |
Correct |
111 ms |
15708 KB |
Output is correct |
41 |
Correct |
113 ms |
15976 KB |
Output is correct |
42 |
Correct |
113 ms |
15976 KB |
Output is correct |
43 |
Correct |
110 ms |
15812 KB |
Output is correct |
44 |
Correct |
129 ms |
15288 KB |
Output is correct |
45 |
Correct |
111 ms |
15428 KB |
Output is correct |
46 |
Correct |
108 ms |
15220 KB |
Output is correct |
47 |
Correct |
103 ms |
15684 KB |
Output is correct |
48 |
Correct |
105 ms |
15656 KB |
Output is correct |
49 |
Correct |
113 ms |
16284 KB |
Output is correct |
50 |
Correct |
120 ms |
16200 KB |
Output is correct |
51 |
Correct |
114 ms |
16296 KB |
Output is correct |
52 |
Correct |
114 ms |
16300 KB |
Output is correct |
53 |
Correct |
121 ms |
16412 KB |
Output is correct |