#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)2e5 + 10;
ll pf[N], sf[N];
ll ans[N];
int main(){
fastIO;
int n;
cin >> n;
vector<int> A(n);
vector<pii> B(n + 1);
for(int i = 0 ; i <= n; i ++ ){
cin >> B[i].fi;
B[i].se = i;
}
for(int i = 0 ; i < n ; i ++ ){
cin >> A[i];
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
for(int i = 0 ; i < n; i ++ ){
pf[i]=max(B[i].fi-A[i],0);
if(i>0)
pf[i]=max(pf[i],pf[i-1]);
}
int q = n - 1;
for(int i = B.size() - 1; i > 0 ; i -- ){
sf[i] = max(B[i].fi-A[q],0);
sf[i]=max(sf[i],sf[i+1]);
q -- ;
}
ll cur;
for(int i = 0 ; i < B.size(); i ++ ){
cur = 0;
if(i > 0) cur = max(cur, pf[i-1]);
cur = max(cur, sf[i + 1]);
ans[B[i].se] = cur;
}
for(int i = 0 ; i <= n; i ++ )
cout << ans[i] << " ";
cout << "\n";
return 0;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:44:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < B.size(); i ++ ){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
110 ms |
12408 KB |
Output is correct |
34 |
Correct |
123 ms |
12792 KB |
Output is correct |
35 |
Correct |
127 ms |
12408 KB |
Output is correct |
36 |
Correct |
113 ms |
12792 KB |
Output is correct |
37 |
Correct |
115 ms |
13176 KB |
Output is correct |
38 |
Correct |
119 ms |
13048 KB |
Output is correct |
39 |
Correct |
108 ms |
12156 KB |
Output is correct |
40 |
Correct |
110 ms |
12048 KB |
Output is correct |
41 |
Correct |
127 ms |
12228 KB |
Output is correct |
42 |
Correct |
109 ms |
12152 KB |
Output is correct |
43 |
Correct |
107 ms |
12024 KB |
Output is correct |
44 |
Correct |
110 ms |
11772 KB |
Output is correct |
45 |
Correct |
109 ms |
11772 KB |
Output is correct |
46 |
Correct |
107 ms |
11644 KB |
Output is correct |
47 |
Correct |
104 ms |
11896 KB |
Output is correct |
48 |
Correct |
106 ms |
11896 KB |
Output is correct |
49 |
Correct |
113 ms |
12408 KB |
Output is correct |
50 |
Correct |
128 ms |
12408 KB |
Output is correct |
51 |
Correct |
114 ms |
12408 KB |
Output is correct |
52 |
Correct |
116 ms |
12592 KB |
Output is correct |
53 |
Correct |
110 ms |
12408 KB |
Output is correct |