#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<long long,long long> ii;
const int N = 2e5+5;
ii a[N];
long long b[N];
long long res[N],n;
long long k[N][2],dp[N];
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i=0;i<n+1;i++) {
cin >> a[i].F;
a[i].S = i;
}
sort(a,a+n+1);
for (int i=0;i<n;i++)
cin >> b[i];
sort(b,b+n);
for (int i=n-1;i>=0;i--) {
k[i][0] = a[i].F - b[i];
k[i][1] = a[i+1].F - b[i];
k[i][0] = max(k[i][0],0ll);
k[i][1] = max(k[i][1],0ll);
// cout << k[i][1] << " ";
}
//cout << endl;
dp[0] = k[0][0];
for (int i=1;i<n;i++) dp[i] = max(dp[i-1],k[i][0]);
res[a[n].S] = dp[n-1];
long long s = 0;
for (int i=n-1;i>=0;i--) {
s = max(s,k[i][1]);
res[a[i].S] = s;
if (i>0) res[a[i].S] = max(res[a[i].S],dp[i-1]);
// cout <<s << " ";
}
for (int i=0;i<=n;i++) cout << res[i] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
484 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
392 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
484 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
392 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
123 ms |
16072 KB |
Output is correct |
34 |
Correct |
110 ms |
16564 KB |
Output is correct |
35 |
Correct |
103 ms |
16068 KB |
Output is correct |
36 |
Correct |
107 ms |
16480 KB |
Output is correct |
37 |
Correct |
110 ms |
17096 KB |
Output is correct |
38 |
Correct |
116 ms |
16840 KB |
Output is correct |
39 |
Correct |
107 ms |
15812 KB |
Output is correct |
40 |
Correct |
104 ms |
15708 KB |
Output is correct |
41 |
Correct |
105 ms |
15972 KB |
Output is correct |
42 |
Correct |
106 ms |
15940 KB |
Output is correct |
43 |
Correct |
108 ms |
15872 KB |
Output is correct |
44 |
Correct |
104 ms |
15228 KB |
Output is correct |
45 |
Correct |
103 ms |
15472 KB |
Output is correct |
46 |
Correct |
102 ms |
15300 KB |
Output is correct |
47 |
Correct |
102 ms |
15716 KB |
Output is correct |
48 |
Correct |
99 ms |
15604 KB |
Output is correct |
49 |
Correct |
110 ms |
16212 KB |
Output is correct |
50 |
Correct |
109 ms |
16384 KB |
Output is correct |
51 |
Correct |
119 ms |
16304 KB |
Output is correct |
52 |
Correct |
107 ms |
16212 KB |
Output is correct |
53 |
Correct |
111 ms |
16196 KB |
Output is correct |