# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367091 | ritul_kr_singh | Watching (JOI13_watching) | C++17 | 2 ms | 512 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.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
int n, p, q;
int a[2000];
bool possible(int w){
vector<array<int, 2>> res = {{a[0], a[0]}};
for(int i=1; i<n; ++i){
if(res.back()[0] + w - 1 < a[i]){
res.push_back({a[i], a[i]});
}else res.back()[1] = a[i];
}
int x = 0, y = 0;
for(int i=0; i<res.size(); ++i){
if(i+1 < res.size() and res[i+1][1]-res[i][0]+1<=2*w){
y += 1;
i += 1;
}else x += 1;
}
if(y > q){
x += 2*(y-q);
y = q;
}
if(x > p){
y += x-p;
x = p;
}
return x<=p and y<=q;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> p >> q;
for(int i=0; i<n; ++i) cin >> a[i];
sort(a, a+n);
int low = 1, high = 1e9;
while(low < high){
int mid = (low+high)/2;
if(possible(mid)) high = mid;
else low = mid+1;
}
cout << low nl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |