# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
897567 | ThylOne | Rice Hub (IOI11_ricehub) | C++14 | 11 ms | 4704 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 "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> pos;
vector<long long> pref;
long long budget;
int limit;
bool existWithT(int T){
long long sum = 0;
for(int i=0;i<T;i++)sum+=pos[i];
auto computeScore = [&](int x,int l,int r){
long long re = 0;
for(int i = l;i<=r;i++){
re+=abs(x-pos[i]);
}
return re;
};
auto findGoodSegment = [&](int l,int r){
int best = pos[(l+r)/2];
int pos_best = (l+r)/2;
int right_part=pref[r]-pref[pos_best];
right_part-= (r-pos_best)*best;
//cout<<"r"<<right_part<<endl;
int left_part=(pos_best-l+1)*best;
left_part-=(pref[pos_best]-(l==0?0:pref[l-1]));
//cout<<"l"<<left_part<<endl;
int computedScore = right_part+left_part;
if(computedScore<=budget)return true;
return false;
};
if(findGoodSegment(0,T-1))return true;
for(int right=T;right<pos.size();right++){
sum-=pos[right-T];
sum+=pos[right];
if(findGoodSegment(right-T+1,right))return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
budget = B;
pos.resize(R);
pref.resize(R);
limit = L;
int act=0;
for(int i = 0;i<R;i++){
pos[i] = X[i];
act+=pos[i];
pref[i]=act;
}
sort(pos.begin(),pos.end());
int low = 1;
int high = R;
while ((high-low)>1){
int mid = (low+high)/2;
if(existWithT(mid)){
low = mid;
}else{
high = mid;
}
}
if(existWithT(high)){
return high;
}else{
return low;
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |