#include <bits/stdc++.h>
using namespace std;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<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.begin(), B.end());
vector<pair<int, int>> C(n+1);
for(int i = 0; i <= n; i++)
C[i] = {A[i], i};
sort(C.begin(), C.end());
multiset<pair<int, int>> maxdiff;
vector<int> ans(n+1);
for(int i = 0; i < n; i++){
maxdiff.insert({(B[i]-C[i].first), B[i]});
}
ans[C[n].second] = maxdiff.begin()->first;
for(int j = n-1; j >= 0; --j){
int original = (B[j]-C[j].first);
maxdiff.erase(maxdiff.find({original, B[j]}));
maxdiff.insert({(B[j]-C[j+1].first), B[j]});
ans[C[j].second] = maxdiff.begin()->first;
}
for(int i : ans)
cout << max(-i, 0) << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
456 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
360 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
456 KB |
Output is correct |
26 |
Correct |
3 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
456 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
360 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
456 KB |
Output is correct |
26 |
Correct |
3 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
247 ms |
18064 KB |
Output is correct |
34 |
Correct |
233 ms |
18888 KB |
Output is correct |
35 |
Correct |
233 ms |
18320 KB |
Output is correct |
36 |
Correct |
226 ms |
18824 KB |
Output is correct |
37 |
Correct |
226 ms |
19408 KB |
Output is correct |
38 |
Correct |
223 ms |
19120 KB |
Output is correct |
39 |
Correct |
288 ms |
18116 KB |
Output is correct |
40 |
Correct |
290 ms |
17988 KB |
Output is correct |
41 |
Correct |
289 ms |
18216 KB |
Output is correct |
42 |
Correct |
316 ms |
18228 KB |
Output is correct |
43 |
Correct |
311 ms |
17980 KB |
Output is correct |
44 |
Correct |
249 ms |
17600 KB |
Output is correct |
45 |
Correct |
251 ms |
17820 KB |
Output is correct |
46 |
Correct |
250 ms |
17540 KB |
Output is correct |
47 |
Correct |
205 ms |
18008 KB |
Output is correct |
48 |
Correct |
200 ms |
18068 KB |
Output is correct |
49 |
Correct |
296 ms |
18672 KB |
Output is correct |
50 |
Correct |
302 ms |
18628 KB |
Output is correct |
51 |
Correct |
305 ms |
18628 KB |
Output is correct |
52 |
Correct |
293 ms |
18636 KB |
Output is correct |
53 |
Correct |
297 ms |
18628 KB |
Output is correct |