//Author: jainbot27
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()
const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) {
stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) {
bool fst = 1; str res = "{";
for (const auto& x: v) {
if (!fst) res += ", ";
fst = 0; res += ts(x);
}
res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << ts(h); if (sizeof...(t)) cerr << ", ";
DBG(t...); }
#ifdef D
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
template<class T> struct Seg {
const T sta = 0;
T comb(T a, T b){
return max(a, b);
}
int n; vector<T> seg;
void init(int nn){
n = nn;
seg.assign(3*n, sta);
}
void pull(int q){
seg[q] = comb(seg[2*q], seg[2*q+1]);
}
void update(int q, T val){
seg[q+=n] = val; for(q/=2; q!=0;q/=2) pull(q);
}
T query(int l, int r){
T ri = sta, la = sta;
for(l += n, r+= n+1; l < r; l/=2, r/=2){
if(l&1) ri = comb(ri, seg[l++]);
if(r&1) la = comb(seg[--r], la);
}
return comb(ri, la);
}
};
const int N = 2e5 + 10;
ll n, a[N], b[N], c[N], d[N];
Seg<ll> seg1, seg2;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i =0; i < n + 1; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
cin >> b[i];
}
sort(a, a + n + 1);
sort(b, b + n);
seg1.init(n + 2);
seg2.init(n + 2);
for(int i = 0; i < n; i++){
c[i] = abs(b[i] - a[i]);
seg1.update(i, c[i]);
}
for(int i = 0; i < n; i++){
d[i] = abs(b[i] - a[i + 1]);
seg2.update(i, d[i]);
}
for(int i = 0; i < n + 1; i++){
int idx = i-1;
ll ans = seg2.query(idx + 1, n);
if(idx>=0){
ans = max(seg1.query(0, idx), ans);
}
cout << ans << " "[i == n];
}
cout << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |