// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
const int INF = int(1e9) + 10;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
int cur = 0;
V<array<int, 2>> A(N + 1); for(auto& x : A) { cin >> x[0]; x[1] = cur++; }
V<int> B(N); for(auto& x : B) cin >> x;
sort(begin(A), end(A));
sort(begin(B), end(B));
V<int> P(N + 1, 0);
for(int i = 0; i < N; i++) P[i] = max(A[i][0] - B[i], (i-1 >= 0 ? P[i-1] : 0));
V<int> S(N + 1, 0);
for(int i = N; i >= 1; i--) S[i] = max(A[i][0] - B[i-1], (i+1 <= N ? S[i+1] : 0));
// for(auto x : P) cout << x << " ";
// cout << nl;
// for(auto x : S) cout << x << " ";
// cout << nl;
V<int> ans(N + 1);
for(int i = 0; i <= N; i++) {
int I = A[i][1];
if (i-1 >= 0) ans[I] = max(ans[I], P[i - 1]);
if (i+1 <= N) ans[I] = max(ans[I], S[i + 1]);
}
for(auto x : ans) cout << x << " ";
cout << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 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 |
324 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 |
228 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 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 |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
380 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
328 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 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 |
324 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 |
228 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 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 |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
380 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
328 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 |
70 ms |
9980 KB |
Output is correct |
34 |
Correct |
73 ms |
10304 KB |
Output is correct |
35 |
Correct |
71 ms |
9972 KB |
Output is correct |
36 |
Correct |
72 ms |
10512 KB |
Output is correct |
37 |
Correct |
78 ms |
10828 KB |
Output is correct |
38 |
Correct |
75 ms |
10652 KB |
Output is correct |
39 |
Correct |
71 ms |
9684 KB |
Output is correct |
40 |
Correct |
71 ms |
9744 KB |
Output is correct |
41 |
Correct |
74 ms |
9768 KB |
Output is correct |
42 |
Correct |
76 ms |
9904 KB |
Output is correct |
43 |
Correct |
72 ms |
9756 KB |
Output is correct |
44 |
Correct |
69 ms |
9420 KB |
Output is correct |
45 |
Correct |
70 ms |
9360 KB |
Output is correct |
46 |
Correct |
71 ms |
9292 KB |
Output is correct |
47 |
Correct |
71 ms |
9552 KB |
Output is correct |
48 |
Correct |
68 ms |
9420 KB |
Output is correct |
49 |
Correct |
73 ms |
10064 KB |
Output is correct |
50 |
Correct |
74 ms |
10064 KB |
Output is correct |
51 |
Correct |
73 ms |
10056 KB |
Output is correct |
52 |
Correct |
74 ms |
9956 KB |
Output is correct |
53 |
Correct |
73 ms |
9948 KB |
Output is correct |