#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<iomanip>
#include<algorithm>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<deque>
#include<math.h>
#include<assert.h>
using namespace std;
const int64_t INF = 1e18 + 5;
const int64_t mINF = 1e9 + 5;
const int64_t MOD = 1e9 + 7;
const int nbit = 31;
const int nchar = 26;
const int D = 4;
int dr[D] = {1, -1, -1, 1};
int dc[D] = {1, 1, 1, -1};
struct Thing
{
int val;
int id;
Thing(int val_, int id_) : val(val_), id(id_) {}
bool operator < (const Thing& o) const
{
return val < o.val;
}
};
struct Solution
{
int n;
vector<Thing> a;
vector<int> b;
Solution() {}
void solve()
{
cin >> n;
b.resize(n, 0);
for(int i = 0; i <= n; i++)
{
int x;
cin >> x;
a.push_back(Thing(x, i));
}
for(int i = 0; i < n; i++)
{
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> prefix(n + 1, 0);
for(int i = 1; i <= n; i++)
{
int dif = a[i - 1].val - b[i - 1];
prefix[i] = max(prefix[i - 1], max(dif, 0));
}
int suf = 0;
vector<int> ans(n + 1, -1);
for(int i = n; i >= 0; i--)
{
int id = a[i].id;
ans[id] = max(suf, prefix[i]);
int tmp = 0;
if(i != 0) tmp = max(a[i].val - b[i - 1], 0);
suf = max(suf, tmp);
}
for(int i = 0; i <= n; i++)
{
cout << ans[i] << " ";
}
}
int modadd(int t1, int t2)
{
int res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int Abs(int tmp)
{
if(tmp < 0) return -tmp;
return tmp;
}
int64_t MASK(int j)
{
return (1LL << j);
}
bool BIT(int64_t tmp, int j)
{
return (tmp & MASK(j));
}
};
void __setup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__setup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
85 ms |
9148 KB |
Output is correct |
34 |
Correct |
86 ms |
9604 KB |
Output is correct |
35 |
Correct |
82 ms |
9264 KB |
Output is correct |
36 |
Correct |
86 ms |
9748 KB |
Output is correct |
37 |
Correct |
86 ms |
10048 KB |
Output is correct |
38 |
Correct |
94 ms |
9928 KB |
Output is correct |
39 |
Correct |
81 ms |
9028 KB |
Output is correct |
40 |
Correct |
89 ms |
8980 KB |
Output is correct |
41 |
Correct |
85 ms |
9096 KB |
Output is correct |
42 |
Correct |
89 ms |
9028 KB |
Output is correct |
43 |
Correct |
88 ms |
8984 KB |
Output is correct |
44 |
Correct |
96 ms |
8576 KB |
Output is correct |
45 |
Correct |
83 ms |
8592 KB |
Output is correct |
46 |
Correct |
87 ms |
8716 KB |
Output is correct |
47 |
Correct |
74 ms |
8616 KB |
Output is correct |
48 |
Correct |
71 ms |
8700 KB |
Output is correct |
49 |
Correct |
89 ms |
9192 KB |
Output is correct |
50 |
Correct |
90 ms |
9160 KB |
Output is correct |
51 |
Correct |
99 ms |
9184 KB |
Output is correct |
52 |
Correct |
86 ms |
9180 KB |
Output is correct |
53 |
Correct |
91 ms |
9284 KB |
Output is correct |