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 <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 400005;
long long sum[MAXN];
long long loc[MAXN];
int n;
int can(int mid,long long lim){
//mid개를 제거하면 가능한지
for(int L = 0; L <= mid; L++){
int R = mid - L;
int lpos = L + 1;
int rpos = n - R;
int mpos = (lpos + rpos)/2;
long long tot = 0;
long long lcnt = mpos - lpos + 1;
long long rcnt = rpos - mpos;
long long lsum = sum[mpos] - sum[lpos-1];
long long rsum = sum[rpos] - sum[mpos];
tot = (lcnt * loc[mpos]) - (lsum) + (rsum) - (rcnt * loc[mpos]);
if(tot <= lim){
return 1;
}
}
return 0;
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
for(int i = 0; i < R; i++) loc[i+1] = X[i];
for(int i=1;i<=R;i++){
sum[i] += sum[i-1] + loc[i];
}
int low = 0;
int high = R;
while(low<=high){
int mid = (low+high)/2;
if(can(mid,B)){ high = mid - 1; }
else low = mid + 1;
}
return n-(high + 1);
}
# | 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... |