#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
ll INF=LLONG_MAX;
ll b[200222],c[200222],cnt[200222],cnt2[200222],dp[200222],dp2[200222],ans[200222];
vector < pll > a;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int n; cin >> n;
for(int i=0; i<=n; i++){
cin >> c[i];
a.pb({c[i],i});
cnt[i]=0; dp[i]=0;
cnt2[i]=0; dp2[i]=0;
}
for(int i=0; i<n; i++)cin >> b[i];
sort(b,b+n);
sort(a.begin(),a.end());
for(int i=0; i<n; i++){
cnt[i] = max(a[i].fi-b[i],(ll)0);
cnt2[i] = max(a[i+1].fi-b[i],(ll)0);
}
dp[0]=cnt[0];
for(int i=1; i<=n; i++){
dp[i] = max(dp[i-1],cnt[i]);
}
for(int i=n-1; i>=0; i--){
dp2[i] = max(dp2[i+1],cnt2[i]);
}
for(int i=0; i<=n; i++){
ans[a[i].se]=max(dp[i],dp2[i]);
}
for(int i=0; i<=n; i++)cout << ans[i] << ' ';
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
640 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
640 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
113 ms |
15456 KB |
Output is correct |
34 |
Correct |
122 ms |
19936 KB |
Output is correct |
35 |
Correct |
119 ms |
19292 KB |
Output is correct |
36 |
Correct |
118 ms |
19808 KB |
Output is correct |
37 |
Correct |
123 ms |
20448 KB |
Output is correct |
38 |
Correct |
123 ms |
20192 KB |
Output is correct |
39 |
Correct |
124 ms |
19168 KB |
Output is correct |
40 |
Correct |
116 ms |
19044 KB |
Output is correct |
41 |
Correct |
117 ms |
19296 KB |
Output is correct |
42 |
Correct |
128 ms |
19428 KB |
Output is correct |
43 |
Correct |
116 ms |
19044 KB |
Output is correct |
44 |
Correct |
120 ms |
18532 KB |
Output is correct |
45 |
Correct |
122 ms |
18784 KB |
Output is correct |
46 |
Correct |
113 ms |
18528 KB |
Output is correct |
47 |
Correct |
111 ms |
19040 KB |
Output is correct |
48 |
Correct |
117 ms |
19168 KB |
Output is correct |
49 |
Correct |
131 ms |
19716 KB |
Output is correct |
50 |
Correct |
127 ms |
19680 KB |
Output is correct |
51 |
Correct |
119 ms |
19684 KB |
Output is correct |
52 |
Correct |
121 ms |
19680 KB |
Output is correct |
53 |
Correct |
120 ms |
19680 KB |
Output is correct |