#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;
#ifdef LOCAL
#define WOSAOJI freopen("in.txt", "r", stdin);
#else
#define WOSAOJI ios_base::sync_with_stdio(0), cin.tie(0);
#endif
#define chmax(a, b) (a) = (a) > (b) ? (a) : (b)
#define chmin(a, b) (a) = (a) < (b) ? (a) : (b)
const int MAXN = 2e5 + 5;
int n;
int a[MAXN], b[MAXN], c[MAXN];
int st1[MAXN], st2[MAXN];
int pre[MAXN], suf[MAXN];
signed main() {
WOSAOJI
cin >> n;
for (int i = 0; i <= n; i++) cin >> a[i], b[i] = a[i];
for (int i = 0; i < n; i++) cin >> c[i];
sort(b, b + 1 + n);
sort(c, c + n);
for (int i = 0; i < n; i++) {
st1[i] = max(-c[i] + b[i], 0ll);
st2[i] = max(-c[i] + b[i + 1], 0ll);
}
pre[0] = st1[0];
for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], st1[i]);
suf[n - 1] = st2[n - 1];
for (int i = n - 2; i >= 0; i--) suf[i] = max(suf[i + 1], st2[i]);
for (int i = 0; i <= n; i++) {
int it = upper_bound(b, b + n + 1, a[i] - 1) - b;
int ans = suf[it];
if (it != 0) chmax(ans, pre[it - 1]);
cout << ans << " \n"[i == n];
}
}
# |
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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
524 KB |
Output is correct |
18 |
Correct |
1 ms |
472 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
392 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
1 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 |
472 KB |
Output is correct |
31 |
Correct |
1 ms |
472 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
524 KB |
Output is correct |
18 |
Correct |
1 ms |
472 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
392 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
1 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 |
472 KB |
Output is correct |
31 |
Correct |
1 ms |
472 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
110 ms |
15964 KB |
Output is correct |
34 |
Correct |
123 ms |
16856 KB |
Output is correct |
35 |
Correct |
109 ms |
16076 KB |
Output is correct |
36 |
Correct |
111 ms |
16564 KB |
Output is correct |
37 |
Correct |
124 ms |
17112 KB |
Output is correct |
38 |
Correct |
112 ms |
16844 KB |
Output is correct |
39 |
Correct |
109 ms |
15824 KB |
Output is correct |
40 |
Correct |
142 ms |
15908 KB |
Output is correct |
41 |
Correct |
111 ms |
15948 KB |
Output is correct |
42 |
Correct |
108 ms |
15908 KB |
Output is correct |
43 |
Correct |
114 ms |
15792 KB |
Output is correct |
44 |
Correct |
112 ms |
15340 KB |
Output is correct |
45 |
Correct |
107 ms |
15476 KB |
Output is correct |
46 |
Correct |
142 ms |
15276 KB |
Output is correct |
47 |
Correct |
79 ms |
15688 KB |
Output is correct |
48 |
Correct |
78 ms |
15700 KB |
Output is correct |
49 |
Correct |
114 ms |
16300 KB |
Output is correct |
50 |
Correct |
116 ms |
16220 KB |
Output is correct |
51 |
Correct |
121 ms |
16308 KB |
Output is correct |
52 |
Correct |
114 ms |
16248 KB |
Output is correct |
53 |
Correct |
120 ms |
16200 KB |
Output is correct |