#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef FourLeafClover
freopen("input", "r", stdin);
#endif // FourLeafCLover
int n; cin >> n;
vector<pair<int, int> > a(n + 1);
for (int i = 0; i < sz(a); ++i) {
cin >> a[i].first;
a[i].second = i;
}
sort(all(a) );
vector<int> b(n);
for (int i = 0; i < sz(b); ++i) cin >> b[i];
sort(all(b) );
vector<int> ans(n + 1);
vector<int> pref(n);
for (int i = 0; i < sz(pref); ++i) {
if (i) pref[i] = pref[i - 1];
asMx(pref[i], max(0, a[i].first - b[i]) );
}
vector<int> suff(n);
for (int i = n - 1; ~i; --i) {
if (i + 1 < sz(suff) ) suff[i] = suff[i + 1];
asMx(suff[i], max(0, a[i + 1].first - b[i]) );
}
for (int i = 0; i <= n; ++i) {
if (i) asMx(ans[ a[i].second ], pref[i - 1]);
if (i < n) asMx(ans[ a[i].second ], suff[i]);
}
for (auto i : ans) cout << i << ' ';
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 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 |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
380 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
380 KB |
Output is correct |
32 |
Correct |
6 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 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 |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
380 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
380 KB |
Output is correct |
32 |
Correct |
6 ms |
380 KB |
Output is correct |
33 |
Correct |
119 ms |
6392 KB |
Output is correct |
34 |
Correct |
119 ms |
6600 KB |
Output is correct |
35 |
Correct |
114 ms |
6392 KB |
Output is correct |
36 |
Correct |
114 ms |
6776 KB |
Output is correct |
37 |
Correct |
118 ms |
7032 KB |
Output is correct |
38 |
Correct |
116 ms |
6904 KB |
Output is correct |
39 |
Correct |
113 ms |
6136 KB |
Output is correct |
40 |
Correct |
112 ms |
6136 KB |
Output is correct |
41 |
Correct |
134 ms |
6136 KB |
Output is correct |
42 |
Correct |
112 ms |
6140 KB |
Output is correct |
43 |
Correct |
118 ms |
6112 KB |
Output is correct |
44 |
Correct |
110 ms |
5732 KB |
Output is correct |
45 |
Correct |
112 ms |
5752 KB |
Output is correct |
46 |
Correct |
118 ms |
5752 KB |
Output is correct |
47 |
Correct |
111 ms |
5624 KB |
Output is correct |
48 |
Correct |
110 ms |
5624 KB |
Output is correct |
49 |
Correct |
120 ms |
6264 KB |
Output is correct |
50 |
Correct |
120 ms |
6264 KB |
Output is correct |
51 |
Correct |
115 ms |
6264 KB |
Output is correct |
52 |
Correct |
120 ms |
6264 KB |
Output is correct |
53 |
Correct |
114 ms |
6264 KB |
Output is correct |