#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll
const int N = 2e5 + 5;
const int oo = 1e9 + 5;
int n, ans[N];
pii a[N], b[N];
multiset <int> st;
void solve() {
cin >> n;
for (int i = 1; i <= n+1; ++i) {
cin >> a[i].F;
a[i].S = i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i].F;
b[i].S = i;
}
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; ++i) {
st.insert(max(a[i].F - b[i].F, 0));
}
ans[a[n+1].S] = *st.rbegin();
for (int i = n; i >= 1; --i) {
st.erase(st.find(max(a[i].F - b[i].F, 0))); // old a[i] - b[i]
st.insert(max(a[i+1].F - b[i].F, 0)); // new a[i+1] - b[i]
ans[a[i].S] = *st.rbegin();
}
for (int i = 1; i <= n+1; ++i) {
cout << ans[i] <<" ";
}
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
//cin >> tests;
while (tests --) {
solve();
}
return 0;
}
/*
Just Chalish!
*/
Compilation message
ho_t1.cpp:74:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main () {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
540 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
540 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
33 |
Correct |
241 ms |
18412 KB |
Output is correct |
34 |
Correct |
260 ms |
19180 KB |
Output is correct |
35 |
Correct |
228 ms |
18540 KB |
Output is correct |
36 |
Correct |
251 ms |
18924 KB |
Output is correct |
37 |
Correct |
264 ms |
19436 KB |
Output is correct |
38 |
Correct |
242 ms |
19436 KB |
Output is correct |
39 |
Correct |
302 ms |
18156 KB |
Output is correct |
40 |
Correct |
306 ms |
18156 KB |
Output is correct |
41 |
Correct |
322 ms |
18572 KB |
Output is correct |
42 |
Correct |
297 ms |
18412 KB |
Output is correct |
43 |
Correct |
320 ms |
18156 KB |
Output is correct |
44 |
Correct |
208 ms |
17644 KB |
Output is correct |
45 |
Correct |
205 ms |
17900 KB |
Output is correct |
46 |
Correct |
207 ms |
17644 KB |
Output is correct |
47 |
Correct |
210 ms |
18156 KB |
Output is correct |
48 |
Correct |
222 ms |
18176 KB |
Output is correct |
49 |
Correct |
317 ms |
18796 KB |
Output is correct |
50 |
Correct |
306 ms |
18668 KB |
Output is correct |
51 |
Correct |
294 ms |
18668 KB |
Output is correct |
52 |
Correct |
310 ms |
18752 KB |
Output is correct |
53 |
Correct |
308 ms |
18668 KB |
Output is correct |