#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const long long N = 2e5+10;
const long long mod = 1e9+7;
const long long inf = 1e18;
vector<int>a(N);
bool cmp(int i,int j) {
return a[i] < a[j];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int>b(n+1);
for(int i=1;i<=n+1;i++) cin >> a[i];
for(int i=1;i<=n;i++) cin >> b[i];
sort(b.begin()+1,b.end());
vector<int>order(n+2),ans(n+2);
iota(order.begin()+1,order.end(),1);
sort(order.begin()+1,order.end(),cmp);
multiset<int>ms;
for(int i=2;i<=n+1;i++) ms.insert(max(0ll,a[order[i]]-b[i-1]));
//for(int i=1;i<=n+1;i++) cout << a[order[i]] << ' ';
for(int i=1;i<=n+1;i++) {
//cout << order[i] << ' ';
ans[order[i]] = *(--ms.end());
if(i <= n) ms.erase(ms.find(max(0ll,a[order[i+1]]-b[i])));
if(i <= n) ms.insert(max(0ll,a[order[i]]-b[i]));
}
for(int i=1;i<=n+1;i++) cout << ans[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1900 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1968 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
2004 KB |
Output is correct |
18 |
Correct |
2 ms |
2004 KB |
Output is correct |
19 |
Correct |
2 ms |
2040 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Correct |
2 ms |
2004 KB |
Output is correct |
22 |
Correct |
2 ms |
2004 KB |
Output is correct |
23 |
Correct |
2 ms |
2040 KB |
Output is correct |
24 |
Correct |
2 ms |
2004 KB |
Output is correct |
25 |
Correct |
2 ms |
1952 KB |
Output is correct |
26 |
Correct |
2 ms |
2004 KB |
Output is correct |
27 |
Correct |
2 ms |
2004 KB |
Output is correct |
28 |
Correct |
2 ms |
2004 KB |
Output is correct |
29 |
Correct |
2 ms |
2004 KB |
Output is correct |
30 |
Correct |
2 ms |
2004 KB |
Output is correct |
31 |
Correct |
2 ms |
2004 KB |
Output is correct |
32 |
Correct |
2 ms |
2004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1900 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1968 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
2004 KB |
Output is correct |
18 |
Correct |
2 ms |
2004 KB |
Output is correct |
19 |
Correct |
2 ms |
2040 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Correct |
2 ms |
2004 KB |
Output is correct |
22 |
Correct |
2 ms |
2004 KB |
Output is correct |
23 |
Correct |
2 ms |
2040 KB |
Output is correct |
24 |
Correct |
2 ms |
2004 KB |
Output is correct |
25 |
Correct |
2 ms |
1952 KB |
Output is correct |
26 |
Correct |
2 ms |
2004 KB |
Output is correct |
27 |
Correct |
2 ms |
2004 KB |
Output is correct |
28 |
Correct |
2 ms |
2004 KB |
Output is correct |
29 |
Correct |
2 ms |
2004 KB |
Output is correct |
30 |
Correct |
2 ms |
2004 KB |
Output is correct |
31 |
Correct |
2 ms |
2004 KB |
Output is correct |
32 |
Correct |
2 ms |
2004 KB |
Output is correct |
33 |
Correct |
157 ms |
17896 KB |
Output is correct |
34 |
Correct |
222 ms |
21180 KB |
Output is correct |
35 |
Correct |
164 ms |
20560 KB |
Output is correct |
36 |
Correct |
169 ms |
21300 KB |
Output is correct |
37 |
Correct |
178 ms |
21736 KB |
Output is correct |
38 |
Correct |
159 ms |
21452 KB |
Output is correct |
39 |
Correct |
227 ms |
20472 KB |
Output is correct |
40 |
Correct |
219 ms |
20284 KB |
Output is correct |
41 |
Correct |
265 ms |
20616 KB |
Output is correct |
42 |
Correct |
214 ms |
20556 KB |
Output is correct |
43 |
Correct |
222 ms |
20300 KB |
Output is correct |
44 |
Correct |
155 ms |
19836 KB |
Output is correct |
45 |
Correct |
144 ms |
20016 KB |
Output is correct |
46 |
Correct |
145 ms |
19744 KB |
Output is correct |
47 |
Correct |
127 ms |
20340 KB |
Output is correct |
48 |
Correct |
134 ms |
20324 KB |
Output is correct |
49 |
Correct |
236 ms |
20972 KB |
Output is correct |
50 |
Correct |
234 ms |
20988 KB |
Output is correct |
51 |
Correct |
221 ms |
20968 KB |
Output is correct |
52 |
Correct |
217 ms |
20976 KB |
Output is correct |
53 |
Correct |
253 ms |
20988 KB |
Output is correct |