이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "ricehub.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
vi prefix, suffix;
vi rice;
ll MAX;
int cost(int l, int r){
int m = (l+r)/2;
ll c = prefix[r] - prefix[m] - rice[m] * (r-m);
c += suffix[l] - suffix[m] - (MAX - rice[m]) * (m-l);
return c;
}
bool possible(int l, int r, ll B){
//cout <<l << " " << r << " " << cost(l,r) << endl;
return cost(l, r) <= B;
}
int besthub(int R, int L, int X[], ll B)
{
MAX = L;
rice.resize(R);
for(int i = 0; i < R; i++) rice[i] = X[i];
prefix.assign(R+1, 0); suffix.assign(R+1, 0);
for(int i = 1; i <= R; i++) prefix[i] = prefix[i-1] + rice[i-1];
for(int i = R-1; i >= 0; i--) suffix[i] = suffix[i+1] + L - rice[i];
ll l = 0, r = 0;
ll best = -1;
while(!(l == R and r == R)){
while(possible(l, r, B)){
best = max(best, r-l);
if(r < R) r++;
else break;
}
l++;
}
return best;
}
/*
int test[] = {1, 2, 10, 12, 14};
int main(){
cout << besthub(5, 20, test, 6)<<endl;
}
*/
# | 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... |