#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using namespace std;
const int nax = 2e5 + 111;
int n;
pair<int,int> a[nax];
int b[nax];
int s[nax][2];
int ans[nax];
int main() {
scanf ("%d", &n);
rep(i, 1, n + 1) {
scanf ("%d", &a[i].fi);
a[i].se = i;
}
rep(i, 1, n) scanf ("%d", b + i);
sort(b + 1, b + n + 1);
sort(a + 1, a + n + 2);
rep(i, 1, n) {
s[i][0] = max(0, a[i].fi - b[i]);
s[i][1] = max(0, a[i + 1].fi - b[i]);
}
rep(i, 1, n) s[i][0] = max(s[i][0], s[i - 1][0]);
per(i, 1, n) s[i][1] = max(s[i][1], s[i + 1][1]);
rep(i, 1, n + 1) {
// printf ("%d %d %d\n", i, s[i - 1][0], s[i][1]);
int x = (i > 0 ? s[i - 1][0] : 0);
x = max(x, s[i][1]);
ans[a[i].se] = x;
}
rep(i, 1, n + 1) printf ("%d ", ans[i]);
return 0;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &n);
~~~~~~^~~~~~~~~~
ho_t1.cpp:25:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &a[i].fi);
~~~~~~^~~~~~~~~~~~~~~~
ho_t1.cpp:28:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
rep(i, 1, n) scanf ("%d", b + i);
~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 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 |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 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 |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 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 |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
7 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 |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
7 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 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 |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
4 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 |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
7 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 |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
7 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
135 ms |
6392 KB |
Output is correct |
34 |
Correct |
135 ms |
6520 KB |
Output is correct |
35 |
Correct |
139 ms |
6520 KB |
Output is correct |
36 |
Correct |
134 ms |
6776 KB |
Output is correct |
37 |
Correct |
136 ms |
7032 KB |
Output is correct |
38 |
Correct |
136 ms |
6904 KB |
Output is correct |
39 |
Correct |
143 ms |
6008 KB |
Output is correct |
40 |
Correct |
139 ms |
6008 KB |
Output is correct |
41 |
Correct |
136 ms |
6136 KB |
Output is correct |
42 |
Correct |
146 ms |
6136 KB |
Output is correct |
43 |
Correct |
134 ms |
6008 KB |
Output is correct |
44 |
Correct |
137 ms |
5752 KB |
Output is correct |
45 |
Correct |
139 ms |
5752 KB |
Output is correct |
46 |
Correct |
132 ms |
5752 KB |
Output is correct |
47 |
Correct |
115 ms |
5556 KB |
Output is correct |
48 |
Correct |
122 ms |
5696 KB |
Output is correct |
49 |
Correct |
139 ms |
6136 KB |
Output is correct |
50 |
Correct |
146 ms |
6264 KB |
Output is correct |
51 |
Correct |
144 ms |
6264 KB |
Output is correct |
52 |
Correct |
146 ms |
6312 KB |
Output is correct |
53 |
Correct |
146 ms |
6268 KB |
Output is correct |