#include<bits/stdc++.h>
#define int long long
using namespace std ;
// n caras - bj é o inicial, ai o q ele pode escolher
// oddity - max(a-b, 0) - max min p cada k (oq o ceo pega)
// pega i i -> liga - bi + ai+1 (mlr doq dxr p outro)
const int maxn = 2e5 + 5 ;
multiset<int> ligs ;
int n, c[maxn], b[maxn] ;
pair<int,int> a[maxn] ;
int32_t main(){
ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
cin >> n ;
for(int i = 1 ; i <= n + 1 ; i++){
int aa ; cin >> aa ;
a[i]= {aa, i} ;
}
for(int i = 1 ; i <= n ; i++) cin >> b[i] ;
sort(b + 1, b + 1 + n) ; sort(a + 1, a + 2 + n) ;
//começo
for(int i = 1 ; i <= n ; i++) ligs.insert(max(0LL, a[i].first - b[i])) ;
auto it = ligs.end() ; it-- ;
c[a[n+1].second] = (*it) ;
for(int i = n ; i > 0 ; i--){
ligs.erase(ligs.find(max(0LL, a[i].first - b[i]))) ;
ligs.insert(max(0LL, a[i+1].first - b[i])) ;
auto it = ligs.end() ; it-- ;
c[a[i].second] = (*it) ;
}
for(int i = 1 ; i <= n + 1 ; i++) cout << c[i] << " " ;
cout << "\n" ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
472 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
476 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
472 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
476 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
209 ms |
19192 KB |
Output is correct |
34 |
Correct |
194 ms |
20228 KB |
Output is correct |
35 |
Correct |
197 ms |
19572 KB |
Output is correct |
36 |
Correct |
186 ms |
20220 KB |
Output is correct |
37 |
Correct |
206 ms |
20768 KB |
Output is correct |
38 |
Correct |
175 ms |
20440 KB |
Output is correct |
39 |
Correct |
230 ms |
19448 KB |
Output is correct |
40 |
Correct |
229 ms |
19236 KB |
Output is correct |
41 |
Correct |
216 ms |
19588 KB |
Output is correct |
42 |
Correct |
248 ms |
19468 KB |
Output is correct |
43 |
Correct |
205 ms |
19340 KB |
Output is correct |
44 |
Correct |
178 ms |
18868 KB |
Output is correct |
45 |
Correct |
175 ms |
18996 KB |
Output is correct |
46 |
Correct |
171 ms |
18696 KB |
Output is correct |
47 |
Correct |
174 ms |
19424 KB |
Output is correct |
48 |
Correct |
174 ms |
19404 KB |
Output is correct |
49 |
Correct |
222 ms |
20020 KB |
Output is correct |
50 |
Correct |
228 ms |
19984 KB |
Output is correct |
51 |
Correct |
233 ms |
19960 KB |
Output is correct |
52 |
Correct |
233 ms |
20004 KB |
Output is correct |
53 |
Correct |
234 ms |
20008 KB |
Output is correct |