#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int n;
int b[N], odd[N], ans[N];
vector<pair<int, int>> a;
void read() {
cin >> n;
for(int i = 0; i <= n; i++) {
int x; cin >> x;
a.push_back({x, i});
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++)
cin >> b[i];
sort(b, b+n);
}
//segment tree
int st[4*N];
void update(int idx, int l, int r, int x, int val) {
if(l == r && l != x) return;
if(l == r && l == x) {
st[idx] = val;
return;
}
int lc = idx<<1, rc = lc|1;
update(lc, l, (l+r)/2, x, val);
update(rc, (l+r)/2+1, r, x, val);
st[idx] = max(st[lc], st[rc]);
}
int query(int idx, int l, int r, int x, int y) {
if(r < x || y < l) return 0;
else if(x <= l && r <= y) return st[idx];
int lc = idx<<1, rc = lc|1;
int lq = query(lc, l, (l+r)/2, x, y);
int rq = query(rc, (l+r)/2+1, r, x, y);
return max(lq, rq);
}
void solve() {
memset(st, 0, sizeof st);
for(int i = 0; i < n; i++)
update(1, 0, n-1, i, max(0, a[i+1].first - b[i]));
for(int i = 0; i < n; i++) {
ans[a[i].second] = query(1, 0, n-1, 0, n-1);
update(1, 0, n-1, i, max(0, a[i].first - b[i]));
}
ans[a[n].second] = query(1, 0, n-1, 0, n-1);
for(int i = 0; i < n+1; i++)
cout << ans[i] << " \n"[i==n];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
6 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
6 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
6 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
6 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
7 ms |
3456 KB |
Output is correct |
14 |
Correct |
16 ms |
3456 KB |
Output is correct |
15 |
Correct |
32 ms |
3584 KB |
Output is correct |
16 |
Correct |
8 ms |
3456 KB |
Output is correct |
17 |
Correct |
47 ms |
3576 KB |
Output is correct |
18 |
Correct |
36 ms |
3584 KB |
Output is correct |
19 |
Correct |
43 ms |
3576 KB |
Output is correct |
20 |
Correct |
42 ms |
3504 KB |
Output is correct |
21 |
Correct |
44 ms |
3584 KB |
Output is correct |
22 |
Correct |
40 ms |
3576 KB |
Output is correct |
23 |
Correct |
42 ms |
3576 KB |
Output is correct |
24 |
Correct |
42 ms |
3576 KB |
Output is correct |
25 |
Correct |
55 ms |
3584 KB |
Output is correct |
26 |
Correct |
48 ms |
3576 KB |
Output is correct |
27 |
Correct |
48 ms |
3584 KB |
Output is correct |
28 |
Correct |
53 ms |
3576 KB |
Output is correct |
29 |
Correct |
44 ms |
3580 KB |
Output is correct |
30 |
Correct |
48 ms |
3580 KB |
Output is correct |
31 |
Correct |
55 ms |
3576 KB |
Output is correct |
32 |
Correct |
59 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3456 KB |
Output is correct |
4 |
Correct |
6 ms |
3456 KB |
Output is correct |
5 |
Correct |
6 ms |
3456 KB |
Output is correct |
6 |
Correct |
7 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
3456 KB |
Output is correct |
8 |
Correct |
6 ms |
3456 KB |
Output is correct |
9 |
Correct |
7 ms |
3456 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
6 ms |
3456 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
7 ms |
3456 KB |
Output is correct |
14 |
Correct |
16 ms |
3456 KB |
Output is correct |
15 |
Correct |
32 ms |
3584 KB |
Output is correct |
16 |
Correct |
8 ms |
3456 KB |
Output is correct |
17 |
Correct |
47 ms |
3576 KB |
Output is correct |
18 |
Correct |
36 ms |
3584 KB |
Output is correct |
19 |
Correct |
43 ms |
3576 KB |
Output is correct |
20 |
Correct |
42 ms |
3504 KB |
Output is correct |
21 |
Correct |
44 ms |
3584 KB |
Output is correct |
22 |
Correct |
40 ms |
3576 KB |
Output is correct |
23 |
Correct |
42 ms |
3576 KB |
Output is correct |
24 |
Correct |
42 ms |
3576 KB |
Output is correct |
25 |
Correct |
55 ms |
3584 KB |
Output is correct |
26 |
Correct |
48 ms |
3576 KB |
Output is correct |
27 |
Correct |
48 ms |
3584 KB |
Output is correct |
28 |
Correct |
53 ms |
3576 KB |
Output is correct |
29 |
Correct |
44 ms |
3580 KB |
Output is correct |
30 |
Correct |
48 ms |
3580 KB |
Output is correct |
31 |
Correct |
55 ms |
3576 KB |
Output is correct |
32 |
Correct |
59 ms |
3584 KB |
Output is correct |
33 |
Execution timed out |
1089 ms |
5864 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |