#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 1e9 + 7;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n;
int a[n + 1], b[n];
for (int i = 0; i <= n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> b[i];
sort(b, b + n);
vector<pair<int, int>> v;
for (int i = 0; i <= n; ++i) v.push_back({a[i], i});
int res[n + 1], suff[n + 1];
sort(all(v));
suff[n] = max(v[n].first - b[n - 1], 0ll);
for (int i = n - 1; i > 0; --i) {
suff[i] = max(suff[i + 1], max(v[i].first - b[i - 1], 0ll));
}
int cur = 0;
for (int i = 0; i < n; ++i) {
res[v[i].second] = max(cur, suff[i + 1]);
chmax(cur, max(v[i].first - b[i], 0ll));
}
res[v[n].second] = 0;
for (int i = 0; i < n; ++i) {
chmax(res[v[n].second], v[i].first - b[i]);
}
for (int i = 0; i <= n; ++i) cout << res[i] << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 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 |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 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 |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
516 KB |
Output is correct |
33 |
Correct |
71 ms |
14960 KB |
Output is correct |
34 |
Correct |
75 ms |
15552 KB |
Output is correct |
35 |
Correct |
72 ms |
14780 KB |
Output is correct |
36 |
Correct |
74 ms |
15296 KB |
Output is correct |
37 |
Correct |
76 ms |
15552 KB |
Output is correct |
38 |
Correct |
76 ms |
16436 KB |
Output is correct |
39 |
Correct |
86 ms |
14528 KB |
Output is correct |
40 |
Correct |
73 ms |
14964 KB |
Output is correct |
41 |
Correct |
74 ms |
15504 KB |
Output is correct |
42 |
Correct |
72 ms |
14536 KB |
Output is correct |
43 |
Correct |
77 ms |
14524 KB |
Output is correct |
44 |
Correct |
71 ms |
13844 KB |
Output is correct |
45 |
Correct |
73 ms |
15004 KB |
Output is correct |
46 |
Correct |
71 ms |
14396 KB |
Output is correct |
47 |
Correct |
71 ms |
15176 KB |
Output is correct |
48 |
Correct |
69 ms |
15296 KB |
Output is correct |
49 |
Correct |
87 ms |
14784 KB |
Output is correct |
50 |
Correct |
78 ms |
14780 KB |
Output is correct |
51 |
Correct |
79 ms |
14912 KB |
Output is correct |
52 |
Correct |
75 ms |
14792 KB |
Output is correct |
53 |
Correct |
74 ms |
14956 KB |
Output is correct |