#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n;
cin >> n;
vi a(n+1), b(n);
for(int i = 0; i <= n; i++)
cin >> a[i];
for(int i = 0; i < n; i++)
cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> diff_same(n), diff_next(n);
for(int i = 0; i < n; i++){
diff_same[i] = max(a[i] - b[i], 0);
diff_next[i] = max(a[i+1] - b[i], 0);
}
vector<vi> sparse_same(n+1, vi(26)), sparse_next(n+1, vi(26));
for(int i = 1; i <= n; i++){
sparse_same[i][0] = diff_same[i-1];
sparse_next[i][0] = diff_next[i-1];
}
for(int j = 1; j < 26; j++){
for(int i = 1; i + (1 << j) - 1 <= n; i++){
sparse_same[i][j] = max(sparse_same[i][j-1], sparse_same[i + (1 << (j-1))][j-1]);
sparse_next[i][j] = max(sparse_next[i][j-1], sparse_next[i + (1 << (j-1))][j-1]);
}
}
for(int i = 1; i <= n+1; i++){
if(i == n+1){
int l = 1, r = n;
int w = (int)log2(r - l + 1);
cout << max(sparse_same[l][w], sparse_same[r - (1 << w) + 1][w]) << ' ';
} else if(i == 1){
int l = 1, r = n;
int w = (int)log2(r - l + 1);
cout << max(sparse_next[l][w], sparse_next[r - (1 << w) + 1][w]) << ' ';
} else {
int l1 = 1, r1 = i-1, l2 = i, r2 = n;
int w1 = (int)log2(r1 - l1 + 1), w2 = (int)log2(r2 - l2 + 1);
int max1 = max(sparse_same[l1][w1], sparse_same[r1 - (1 << w1) + 1][w1]);
int max2 = max(sparse_next[l2][w2], sparse_next[r2 - (1 << w2) + 1][w2]);
cout << max(max1, max2) << ' ';
}
}
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("test.out", "w", stdout);
//ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |