# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114520 | mosesmayer | Rice Hub (IOI11_ricehub) | C++17 | 22 ms | 2660 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 <algorithm>
typedef long long LL;
LL all[100005];
int besthub(int R, int L, int X[], long long B)
{
for (int i=1; i <= R; i++) all[i] = X[i-1];
std::sort(all+1,all+R+1);
LL left = 1, right = 1, mx = -1, totalSum = 0;
LL median = 1, newmedian;
LL cost = 0;
LL mxInterval = -1;
while (right <= R){
totalSum += all[right];
int range = (right-left+1);
newmedian = (left+right)>>1;
cost += all[right]-all[median];
if (newmedian > median){
while (median < newmedian){
int change = median - left + 1 - (right - median);
cost += 1LL * change * (all[median+1]-all[median]);
median++;
}
}
while (cost > B){
left++;
cost -= all[median] - all[left-1];
while (median < ((left+right)>>1)){
int change = median - left + 1 - (right - median);
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... |