#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
int ans[maxn];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int N; cin >> N;
vector<pair<int,int>> a;
vector<int> b;
for (int i = 0; i < N+1; i++) {
int ai; cin >> ai;
a.push_back({ai,i});
}
for (int i = 0; i < N; i++) {
int bi; cin >> bi;
b.push_back(bi);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
multiset<int> left, right;
for (int i = 0; i < N; i++) {
right.insert(max(0,a[i+1].first-b[i]));
}
for (int i = 0; i < N+1; i++) {
int mx = 0;
if (!left.empty()) mx = max(mx,*left.rbegin());
if (!right.empty()) mx = max(mx,*right.rbegin());
ans[a[i].second] = mx;
auto it = right.find(max(0,a[i+1].first-b[i]));
if (it != right.end()) right.erase(it);
left.insert(max(0,a[i].first-b[i]));
}
for (int i = 0; i < N+1; i++) {
cout << ans[i] << " \n"[i==N];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
380 KB |
Output is correct |
17 |
Correct |
6 ms |
504 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
6 ms |
508 KB |
Output is correct |
22 |
Correct |
7 ms |
504 KB |
Output is correct |
23 |
Correct |
6 ms |
504 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
6 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
6 ms |
504 KB |
Output is correct |
31 |
Correct |
6 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
380 KB |
Output is correct |
17 |
Correct |
6 ms |
504 KB |
Output is correct |
18 |
Correct |
6 ms |
504 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
6 ms |
508 KB |
Output is correct |
22 |
Correct |
7 ms |
504 KB |
Output is correct |
23 |
Correct |
6 ms |
504 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
6 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
504 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
6 ms |
504 KB |
Output is correct |
31 |
Correct |
6 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
504 KB |
Output is correct |
33 |
Correct |
231 ms |
13792 KB |
Output is correct |
34 |
Correct |
249 ms |
14292 KB |
Output is correct |
35 |
Correct |
220 ms |
13928 KB |
Output is correct |
36 |
Correct |
248 ms |
14444 KB |
Output is correct |
37 |
Correct |
255 ms |
14952 KB |
Output is correct |
38 |
Correct |
241 ms |
14696 KB |
Output is correct |
39 |
Correct |
352 ms |
13776 KB |
Output is correct |
40 |
Correct |
318 ms |
13672 KB |
Output is correct |
41 |
Correct |
334 ms |
13928 KB |
Output is correct |
42 |
Correct |
323 ms |
13804 KB |
Output is correct |
43 |
Correct |
353 ms |
13800 KB |
Output is correct |
44 |
Correct |
202 ms |
13160 KB |
Output is correct |
45 |
Correct |
194 ms |
13288 KB |
Output is correct |
46 |
Correct |
193 ms |
13160 KB |
Output is correct |
47 |
Correct |
195 ms |
13412 KB |
Output is correct |
48 |
Correct |
201 ms |
13416 KB |
Output is correct |
49 |
Correct |
337 ms |
14308 KB |
Output is correct |
50 |
Correct |
329 ms |
14188 KB |
Output is correct |
51 |
Correct |
354 ms |
14112 KB |
Output is correct |
52 |
Correct |
336 ms |
14184 KB |
Output is correct |
53 |
Correct |
336 ms |
14184 KB |
Output is correct |