#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pb push_back
#define mp make_pair
#define ll long long int
#define pi pair <int,int>
#define itn int
#define fr first
#define sc second
#define srt(v) sort(v.begin(), v.end())
#define rvs(v) reverse(v.begin(), v.end())
#define mod 1000000007
#define INF 1e18
using namespace std;
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
vector <pi> a;
vector <int> b;
for(int i = 0;i <= n;i++){
int x;
cin >> x;
a.pb({x, i});
}
for(int i = 0;i < n;i++){
int x;
cin >> x;
b.pb(x);
}
srt(a);
srt(b);
int pref[n+1], suf[n+1];
pref[0] = max((0)*(1ll), a[0].fr - b[0]);
for(int i = 1;i < n;i++){
pref[i] = max(pref[i-1], a[i].fr - b[i]);
}
suf[n] = max((0)*(1ll), a[n].fr - b[n-1]);
for(int i = n-1;i > 0;i--){
suf[i] = max(suf[i+1], a[i].fr - b[i-1]);
}
vector <pi> resp;
for(int i = 0;i <= n;i++){
int res;
if(i == 0) res = suf[1];
else if(i == n) res = pref[n-1];
else res = max(pref[i-1], suf[i+1]);
resp.pb({a[i].sc, res});
}
srt(resp);
for(auto v : resp){
cout << v.sc << " ";
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
102 ms |
18996 KB |
Output is correct |
34 |
Correct |
108 ms |
19556 KB |
Output is correct |
35 |
Correct |
121 ms |
19168 KB |
Output is correct |
36 |
Correct |
132 ms |
19604 KB |
Output is correct |
37 |
Correct |
109 ms |
19960 KB |
Output is correct |
38 |
Correct |
123 ms |
19844 KB |
Output is correct |
39 |
Correct |
102 ms |
18812 KB |
Output is correct |
40 |
Correct |
102 ms |
18804 KB |
Output is correct |
41 |
Correct |
104 ms |
18992 KB |
Output is correct |
42 |
Correct |
126 ms |
18872 KB |
Output is correct |
43 |
Correct |
118 ms |
18808 KB |
Output is correct |
44 |
Correct |
100 ms |
18360 KB |
Output is correct |
45 |
Correct |
129 ms |
18488 KB |
Output is correct |
46 |
Correct |
102 ms |
18372 KB |
Output is correct |
47 |
Correct |
96 ms |
18604 KB |
Output is correct |
48 |
Correct |
104 ms |
18592 KB |
Output is correct |
49 |
Correct |
124 ms |
19164 KB |
Output is correct |
50 |
Correct |
110 ms |
19232 KB |
Output is correct |
51 |
Correct |
120 ms |
19252 KB |
Output is correct |
52 |
Correct |
116 ms |
19232 KB |
Output is correct |
53 |
Correct |
120 ms |
19272 KB |
Output is correct |