# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393687 | Karliver | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 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>
#include <fstream>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
typedef complex<ll> G;
const int INF = 1e9 + 1;
const int N = 1e6 + 100;
const double eps = 1e-3;
int besthub(int R, int L, int X[], ll B) {
int l = 0;
int r = 0;
vector<ll> sm(R + 1, 0);
ll cost = 0;
forn(i, R)sm[i + 1] = X[i] + sm[i - 1];
auto upd = [&]() {
int mid = (l + r) / 2;
cost = 0;
cost += (mid - l + 1)* 1ll * X[mid];
cost -= sm[mid + 1] - sm[l];
cost -= (r - mid + 1) * X[mid];
cost += sm[r + 1] - sm[mid];
};
int ans = 0;
while(l < R) {
while(r < R - 1 && cost <= B) {
++r;
upd();
}
if(cost > B) {
r--;
upd();
}
ckma(ans, r - l + 1);
++l;
}
return ans;
}