#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> a(n+1), b(n);
vector<pair<ll, int>> aa;
for(int i = 0; i <= n; i++){
ll x; cin >> x;
a[i] = x;
aa.pb({x, i});
}
for(ll &x: b) cin >> x;
sort(a.begin(), a.end());
sort(aa.begin(), aa.end());
sort(b.begin(), b.end());
vector<ll> dpa(n, 0), dpb(n, 0);
dpa[0] = max(a[0]-b[0], 0LL);
dpb[n-1] = max(a[n] - b[n-1], 0LL);
for(int i = 1; i < n; i++) dpa[i] = max(dpa[i-1], max(a[i] - b[i], 0LL));
for(int i = n-2; i >= 0; i--) dpb[i] = max(dpb[i+1], max(a[i+1] - b[i], 0LL));
for(int i = 0; i <= n; i++){
aa[i].f = i;
ll tmp = aa[i].f;
aa[i].f = aa[i].sc;
aa[i].sc = tmp;
}
sort(aa.begin(), aa.end());
for(int i = 0; i <= n; i++){
int in = aa[i].sc;
ll ans = 0;
if(in > 0) ans = max(ans, dpa[in-1]);
if(in < n) ans = max(ans, dpb[in]);
cout << ans << " ";
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 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 |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
640 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 |
2 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 |
640 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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 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 |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
640 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 |
2 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 |
640 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 |
158 ms |
14556 KB |
Output is correct |
34 |
Correct |
169 ms |
15080 KB |
Output is correct |
35 |
Correct |
159 ms |
14716 KB |
Output is correct |
36 |
Correct |
151 ms |
15324 KB |
Output is correct |
37 |
Correct |
161 ms |
15580 KB |
Output is correct |
38 |
Correct |
155 ms |
15436 KB |
Output is correct |
39 |
Correct |
148 ms |
14428 KB |
Output is correct |
40 |
Correct |
151 ms |
14304 KB |
Output is correct |
41 |
Correct |
146 ms |
14556 KB |
Output is correct |
42 |
Correct |
153 ms |
14428 KB |
Output is correct |
43 |
Correct |
144 ms |
14304 KB |
Output is correct |
44 |
Correct |
142 ms |
14052 KB |
Output is correct |
45 |
Correct |
150 ms |
14044 KB |
Output is correct |
46 |
Correct |
154 ms |
13896 KB |
Output is correct |
47 |
Correct |
138 ms |
14172 KB |
Output is correct |
48 |
Correct |
128 ms |
14172 KB |
Output is correct |
49 |
Correct |
190 ms |
14876 KB |
Output is correct |
50 |
Correct |
156 ms |
14812 KB |
Output is correct |
51 |
Correct |
152 ms |
14812 KB |
Output is correct |
52 |
Correct |
159 ms |
14996 KB |
Output is correct |
53 |
Correct |
164 ms |
14940 KB |
Output is correct |