제출 #765220

#제출 시각아이디문제언어결과실행 시간메모리
765220yusuf12360Watching (JOI13_watching)C++14
0 / 100
3 ms340 KiB
#include<bits/stdc++.h> #define int long long using namespace std; vector<int> a; int n; int binser(int x) { int l=0, r=n-1, ans=0; while(l<=r) { int mid=(l+r)/2; if(a[mid]<x) ans=mid, l=mid+1; else r=mid-1; } return ans; } bool can(int w, int p, int q) { int idx=0; while(idx<n) { if(p>1 && q) { int BIG=binser(a[idx]+2*w); if(BIG==n-1) return 1; int SMALL=binser(a[idx]+w); if(SMALL==n-1) return 1; SMALL=binser(a[SMALL+1]+w); if(SMALL==n-1) return 1; if(SMALL>BIG) p-=2, idx=SMALL; else q--, idx=BIG; } else if(p && q) { int BIG=binser(a[idx]+2*w), SMALL=binser(a[idx]+w); if(BIG==n-1 || SMALL==n-1) return 1; if(BIG==SMALL) p--, idx=SMALL; else q--, idx=BIG; } else if(p) idx=binser(a[idx]+w), p--; else if(q) idx=binser(a[idx]+2*w), q--; else return 0; idx++; } return 1; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int p, q; cin >> n >> p >> q; a.resize(n); for(int &p : a) cin >> p; sort(a.begin(), a.end()); int l=1, r=1e9, w=1e9; while(l<=r) { int mid=(l+r)/2; if(can(mid, p, q)) w=mid, r=mid-1; else l=mid+1; } cout << w << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...