# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364637 | cpp219 | Just Long Neckties (JOI20_ho_t1) | C++14 | 606 ms | 21484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 6;
const ll inf = 1e9 + 7;
typedef pair<int,int> LL;
LL A[N];
ll n,b[N],a[N],ans[N],init,diff[N],Dec,cur;
bool chk(ll m,ll st){
for (ll i = 1;i <= n;i++){
ll nxt = upper_bound(a + 1,a + n + 2,b[i] + m) - a - 1;
if (nxt >= st) nxt--;
if (nxt < i) return 0;
}
return 1;
}
ll bs(ll st){
ll l,m,h; l = 0; h = inf;
while(l <= h){
m = (l + h)/2;
if (chk(m,st)) h = m - 1;
else l = m + 1;
}
return l;
}
set<LL> s;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n;
for (ll i = 1;i <= n + 1;i++) cin>>A[i].fs,A[i].sc = i; sort(A + 1,A + n + 2);
for (ll i = 1;i <= n + 1;i++) a[i] = A[i].fs;
for (ll i = 1;i <= n;i++) cin>>b[i]; sort(b + 1,b + n + 1);
init = cur = bs(1); ans[A[1].sc] = cur;
for (ll i = 1;i <= n;i++) diff[i] = b[i] - a[i + 1] + init,s.insert({diff[i],i});
for (ll i = 2;i <= n + 1;i++){
s.erase({diff[i - 1],i - 1}); diff[i - 1] = b[i - 1] - a[i - 1] + init;
s.insert({diff[i - 1],i - 1});
LL t = *s.begin();
cur -= t.fs - Dec; Dec = t.fs; ans[A[i].sc] = cur;
}
for (ll i = 1;i <= n + 1;i++) cout<<ans[i]<<" ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |