#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n+1);
vector<int> b(n);
vector<int> ind(n+1);
iota(all(ind), 0);
for (auto &it : a) cin >> it;
for (auto &it : b) cin >> it;
sort(all(b));
sort(all(ind), [&](int i, int j) {
return a[i] < a[j];
});
vector<int> ans(n+1);
multiset<int, greater<>> s;
s.insert(0);
for (int i = 0; i < n; ++i) {
s.insert(a[ind[i]] - b[i]);
}
ans[ind[n]] = *s.begin();
for (int i = n - 1; i >= 0; --i) {
s.erase(s.find(a[ind[i]] - b[i]));
s.insert(a[ind[i+1]] - b[i]);
ans[ind[i]] = *s.begin();
}
for (auto a : ans) cout << a << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
456 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
456 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
196 ms |
17336 KB |
Output is correct |
34 |
Correct |
218 ms |
18120 KB |
Output is correct |
35 |
Correct |
186 ms |
17588 KB |
Output is correct |
36 |
Correct |
188 ms |
18072 KB |
Output is correct |
37 |
Correct |
211 ms |
18656 KB |
Output is correct |
38 |
Correct |
213 ms |
18524 KB |
Output is correct |
39 |
Correct |
223 ms |
17316 KB |
Output is correct |
40 |
Correct |
230 ms |
17228 KB |
Output is correct |
41 |
Correct |
227 ms |
17468 KB |
Output is correct |
42 |
Correct |
232 ms |
17408 KB |
Output is correct |
43 |
Correct |
264 ms |
17352 KB |
Output is correct |
44 |
Correct |
238 ms |
16756 KB |
Output is correct |
45 |
Correct |
277 ms |
17036 KB |
Output is correct |
46 |
Correct |
209 ms |
16820 KB |
Output is correct |
47 |
Correct |
164 ms |
17260 KB |
Output is correct |
48 |
Correct |
168 ms |
17236 KB |
Output is correct |
49 |
Correct |
241 ms |
17892 KB |
Output is correct |
50 |
Correct |
255 ms |
17808 KB |
Output is correct |
51 |
Correct |
263 ms |
17896 KB |
Output is correct |
52 |
Correct |
237 ms |
17812 KB |
Output is correct |
53 |
Correct |
250 ms |
17868 KB |
Output is correct |