#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define mp make_pair
using namespace std;
void debug(){
cout << "\n";
}
template<class T, class ...U>
void debug(T a, U ...b){
cout << a << " "; debug(b...);
}
// 2020 A
const int maxN = 200005;
int main(){
int n;
cin >> n;
pii a[maxN];
int b[maxN];
loop(i,0,n+1){
cin >> a[i].ff;
a[i].ss = i + 1;
}
loop(i,0,n){
cin >> b[i];
}
sort(a, a + n + 1);
sort(b, b + n);
vector<pii> dos;
multiset<pii> S;
int ans[maxN] = {0};
loop(i,0,n){
S.ins( mp( max(a[i].ff - b[i], 0), a[i].ss) );
dos.pb(mp( max(a[i].ff - b[i], 0), a[i].ss ));
}
// for(auto &i:S){
// debug(i.ff, i.ss);
// }
ans[a[n].ss] = (prev(S.end()))->ff;
for(int i = n-1; i >= 0; i--){
S.erase(S.find(dos[i]));
S.insert( mp(max(a[i+1].ff - b[i], 0), a[i+1].ss) );
ans[a[i].ss] = (prev(S.end()))->ff;
//debug("ans[", a[i].ss, "] =", ans[a[i].ss]);
}
loop(i,1,n+2){
cout << ans[i] << " ";
} cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
4 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
4 ms |
3540 KB |
Output is correct |
18 |
Correct |
4 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
4 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3424 KB |
Output is correct |
22 |
Correct |
4 ms |
3412 KB |
Output is correct |
23 |
Correct |
4 ms |
3412 KB |
Output is correct |
24 |
Correct |
5 ms |
3540 KB |
Output is correct |
25 |
Correct |
4 ms |
3540 KB |
Output is correct |
26 |
Correct |
5 ms |
3412 KB |
Output is correct |
27 |
Correct |
4 ms |
3540 KB |
Output is correct |
28 |
Correct |
4 ms |
3540 KB |
Output is correct |
29 |
Correct |
4 ms |
3412 KB |
Output is correct |
30 |
Correct |
4 ms |
3540 KB |
Output is correct |
31 |
Correct |
4 ms |
3540 KB |
Output is correct |
32 |
Correct |
4 ms |
3536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
4 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
4 ms |
3540 KB |
Output is correct |
18 |
Correct |
4 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
4 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3424 KB |
Output is correct |
22 |
Correct |
4 ms |
3412 KB |
Output is correct |
23 |
Correct |
4 ms |
3412 KB |
Output is correct |
24 |
Correct |
5 ms |
3540 KB |
Output is correct |
25 |
Correct |
4 ms |
3540 KB |
Output is correct |
26 |
Correct |
5 ms |
3412 KB |
Output is correct |
27 |
Correct |
4 ms |
3540 KB |
Output is correct |
28 |
Correct |
4 ms |
3540 KB |
Output is correct |
29 |
Correct |
4 ms |
3412 KB |
Output is correct |
30 |
Correct |
4 ms |
3540 KB |
Output is correct |
31 |
Correct |
4 ms |
3540 KB |
Output is correct |
32 |
Correct |
4 ms |
3536 KB |
Output is correct |
33 |
Correct |
308 ms |
18888 KB |
Output is correct |
34 |
Correct |
305 ms |
19640 KB |
Output is correct |
35 |
Correct |
314 ms |
19108 KB |
Output is correct |
36 |
Correct |
301 ms |
19660 KB |
Output is correct |
37 |
Correct |
316 ms |
20124 KB |
Output is correct |
38 |
Correct |
297 ms |
20020 KB |
Output is correct |
39 |
Correct |
457 ms |
18968 KB |
Output is correct |
40 |
Correct |
454 ms |
18864 KB |
Output is correct |
41 |
Correct |
439 ms |
19088 KB |
Output is correct |
42 |
Correct |
441 ms |
18996 KB |
Output is correct |
43 |
Correct |
452 ms |
18812 KB |
Output is correct |
44 |
Correct |
358 ms |
18344 KB |
Output is correct |
45 |
Correct |
335 ms |
18616 KB |
Output is correct |
46 |
Correct |
362 ms |
18344 KB |
Output is correct |
47 |
Correct |
323 ms |
18740 KB |
Output is correct |
48 |
Correct |
304 ms |
18728 KB |
Output is correct |
49 |
Correct |
433 ms |
19392 KB |
Output is correct |
50 |
Correct |
468 ms |
19364 KB |
Output is correct |
51 |
Correct |
498 ms |
19364 KB |
Output is correct |
52 |
Correct |
501 ms |
19396 KB |
Output is correct |
53 |
Correct |
520 ms |
19400 KB |
Output is correct |