#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
using ll = long long;
void solve(){
ll n;
cin >> n;
vector<pair<ll, ll>> list_a(n + 1, pair<ll, ll>{0, 0});
vector<ll> list_b(n, 0);
vector<ll> proper_min(n + 1, 0);
vector<ll> improper_min(n + 1, 0);
for(ll i = 0; i <= n; i++){
cin >> list_a[i].first;
list_a[i].second = i;
}
for(ll i = 0; i < n; i++){
cin >> list_b[i];
}
sort(list_a.begin(), list_a.end());
sort(list_b.begin(), list_b.end());
for(ll i = 0; i < n; i++){
proper_min[i + 1] = max(proper_min[i], max((ll)0, list_a[i].first - list_b[i]));
}
for(ll i = n - 1; i >= 0; i--){
improper_min[n - i] = max(improper_min[n - i - 1], max((ll)0, list_a[i + 1].first - list_b[i]));
}
vector<ll> ans(n + 1, 0);
for(ll i = 0; i <= n; i++){
ans[list_a[i].second] = max(proper_min[i], improper_min[n - i]);
}
for(ll i = 0; i <= n; i++){
cout << ans[i] << " ";
}
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
ll t = 1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
544 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
544 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
71 ms |
14508 KB |
Output is correct |
34 |
Correct |
73 ms |
15132 KB |
Output is correct |
35 |
Correct |
70 ms |
14476 KB |
Output is correct |
36 |
Correct |
71 ms |
15052 KB |
Output is correct |
37 |
Correct |
72 ms |
15436 KB |
Output is correct |
38 |
Correct |
71 ms |
15288 KB |
Output is correct |
39 |
Correct |
74 ms |
14380 KB |
Output is correct |
40 |
Correct |
70 ms |
14316 KB |
Output is correct |
41 |
Correct |
73 ms |
14376 KB |
Output is correct |
42 |
Correct |
70 ms |
14312 KB |
Output is correct |
43 |
Correct |
86 ms |
14240 KB |
Output is correct |
44 |
Correct |
68 ms |
13908 KB |
Output is correct |
45 |
Correct |
68 ms |
13972 KB |
Output is correct |
46 |
Correct |
68 ms |
13904 KB |
Output is correct |
47 |
Correct |
66 ms |
14160 KB |
Output is correct |
48 |
Correct |
65 ms |
14164 KB |
Output is correct |
49 |
Correct |
70 ms |
14676 KB |
Output is correct |
50 |
Correct |
71 ms |
14672 KB |
Output is correct |
51 |
Correct |
73 ms |
14788 KB |
Output is correct |
52 |
Correct |
72 ms |
14676 KB |
Output is correct |
53 |
Correct |
82 ms |
14652 KB |
Output is correct |