#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 200005;
int n, C[MXN];
pii a[MXN], b[MXN];
multiset<int> MS;
int f(int a, int b) {
return max(0LL, a - b);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
for (int i = 0; i < n; i++) {
cin >> b[i].first;
b[i].second = i;
}
sort(a, a + n + 1);
sort(b, b + n);
for (int i = 0; i < n; i++) {
MS.insert(f(a[i].first, b[i].first));
}
C[a[n].second] = *MS.rbegin();
for (int i = n - 1; i >= 0; i--) {
MS.erase(MS.find(f(a[i].first, b[i].first)));
MS.insert(f(a[i + 1].first, b[i].first));
C[a[i].second] = *MS.rbegin();
}
for (int i = 0; i <= n; i++) cout << C[i] << ' ';
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 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 |
2 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 |
2 ms |
484 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
480 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 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 |
2 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 |
2 ms |
484 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
480 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
163 ms |
18124 KB |
Output is correct |
34 |
Correct |
194 ms |
19020 KB |
Output is correct |
35 |
Correct |
163 ms |
18344 KB |
Output is correct |
36 |
Correct |
172 ms |
18852 KB |
Output is correct |
37 |
Correct |
176 ms |
19532 KB |
Output is correct |
38 |
Correct |
175 ms |
19176 KB |
Output is correct |
39 |
Correct |
218 ms |
18208 KB |
Output is correct |
40 |
Correct |
211 ms |
18132 KB |
Output is correct |
41 |
Correct |
218 ms |
18216 KB |
Output is correct |
42 |
Correct |
230 ms |
18196 KB |
Output is correct |
43 |
Correct |
224 ms |
18084 KB |
Output is correct |
44 |
Correct |
172 ms |
17624 KB |
Output is correct |
45 |
Correct |
167 ms |
17804 KB |
Output is correct |
46 |
Correct |
168 ms |
17612 KB |
Output is correct |
47 |
Correct |
179 ms |
17964 KB |
Output is correct |
48 |
Correct |
193 ms |
18036 KB |
Output is correct |
49 |
Correct |
225 ms |
18688 KB |
Output is correct |
50 |
Correct |
230 ms |
18596 KB |
Output is correct |
51 |
Correct |
214 ms |
18604 KB |
Output is correct |
52 |
Correct |
261 ms |
18672 KB |
Output is correct |
53 |
Correct |
249 ms |
18676 KB |
Output is correct |