#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#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>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
signed main () {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
pair<int,int> a[n + 1];
int b[n];
for (int i = 0 ; i < n + 1 ; i++) cin >> a[i].first, a[i].second = i;
for (int i = 0 ; i < n ; i++) cin >> b[i];
sort(a, a + n + 1);
sort(b, b + n);
int pref[n];
for (int i = 0 ; i < n ; i++) {
pref[i] = a[i].first - b[i];
if (i) pref[i] = max(pref[i-1], pref[i]);
}
int suff[n+2];
memset(suff, 0, sizeof suff);
for (int i = n - 1 ; i >= 0 ; i--) {
suff[i] = a[i+1].first - b[i];
if (i < n - 1) suff[i] = max(suff[i+1], suff[i]);
}
int c[n+2];
memset(c,0,sizeof c);
for (int i = 0 ; i < n + 1 ; i++) {
c[a[i].second] = 0;
if (i) c[a[i].second] = pref[i-1];
c[a[i].second] = max(c[a[i].second], suff[i]);
}
for (int i = 0 ; i < n + 1 ; i++) cout << c[i] << " ";
}
Compilation message
ho_t1.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
292 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 |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
292 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 |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
94 ms |
10656 KB |
Output is correct |
34 |
Correct |
133 ms |
14636 KB |
Output is correct |
35 |
Correct |
101 ms |
14248 KB |
Output is correct |
36 |
Correct |
106 ms |
14664 KB |
Output is correct |
37 |
Correct |
137 ms |
15064 KB |
Output is correct |
38 |
Correct |
103 ms |
14896 KB |
Output is correct |
39 |
Correct |
100 ms |
13916 KB |
Output is correct |
40 |
Correct |
111 ms |
13968 KB |
Output is correct |
41 |
Correct |
105 ms |
14028 KB |
Output is correct |
42 |
Correct |
96 ms |
13968 KB |
Output is correct |
43 |
Correct |
109 ms |
13972 KB |
Output is correct |
44 |
Correct |
101 ms |
13624 KB |
Output is correct |
45 |
Correct |
108 ms |
13636 KB |
Output is correct |
46 |
Correct |
136 ms |
13580 KB |
Output is correct |
47 |
Correct |
99 ms |
13644 KB |
Output is correct |
48 |
Correct |
104 ms |
13696 KB |
Output is correct |
49 |
Correct |
131 ms |
14308 KB |
Output is correct |
50 |
Correct |
114 ms |
14308 KB |
Output is correct |
51 |
Correct |
110 ms |
14312 KB |
Output is correct |
52 |
Correct |
102 ms |
14240 KB |
Output is correct |
53 |
Correct |
112 ms |
14284 KB |
Output is correct |