#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=2e5+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
optimise;
int n;
cin>>n;
vector<pair<int,int>> a(n+1);
vector<int> b(n);
for (int i = 0; i < n+1; ++i)
{
cin>>a[i].fi;
a[i].se=i;
}
for (int i = 0; i < n; ++i)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int pre[n+1];
int suf[n+1];
pre[0]=max(0,a[0].fi-b[0]);
pre[n]=0;
suf[0]=0;
suf[n]=max(0,a[n].fi-b[n-1]);
for (int i = 1; i < n; ++i)
{
pre[i]=max(max(a[i].fi-b[i],0),pre[i-1]);
}
for (int i = n-1; i > 0; --i)
{
suf[i]=max(max(a[i].fi-b[i-1],0),suf[i+1]);
}
vector<int> ans(n+1);
for (int i = 0; i <= n; ++i)
{
if(i>0&&i<n) ans[a[i].se]=max(pre[i-1],suf[i+1]);
else if(i==0) ans[a[i].se]=suf[i+1];
else ans[a[i].se]=pre[i-1];
}
for (int i = 0; i <= n; ++i)
{
cout <<ans[i]<<" ";
}cout <<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
520 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
520 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
59 ms |
10068 KB |
Output is correct |
34 |
Correct |
73 ms |
10320 KB |
Output is correct |
35 |
Correct |
62 ms |
10068 KB |
Output is correct |
36 |
Correct |
64 ms |
10580 KB |
Output is correct |
37 |
Correct |
64 ms |
10836 KB |
Output is correct |
38 |
Correct |
65 ms |
10672 KB |
Output is correct |
39 |
Correct |
62 ms |
9760 KB |
Output is correct |
40 |
Correct |
69 ms |
9664 KB |
Output is correct |
41 |
Correct |
59 ms |
9872 KB |
Output is correct |
42 |
Correct |
61 ms |
9896 KB |
Output is correct |
43 |
Correct |
61 ms |
9808 KB |
Output is correct |
44 |
Correct |
61 ms |
9448 KB |
Output is correct |
45 |
Correct |
52 ms |
9484 KB |
Output is correct |
46 |
Correct |
56 ms |
9468 KB |
Output is correct |
47 |
Correct |
70 ms |
9528 KB |
Output is correct |
48 |
Correct |
50 ms |
9528 KB |
Output is correct |
49 |
Correct |
61 ms |
10068 KB |
Output is correct |
50 |
Correct |
69 ms |
10064 KB |
Output is correct |
51 |
Correct |
54 ms |
10100 KB |
Output is correct |
52 |
Correct |
56 ms |
10320 KB |
Output is correct |
53 |
Correct |
59 ms |
10324 KB |
Output is correct |