제출 #43664

#제출 시각아이디문제언어결과실행 시간메모리
43664smu201111192Rice Hub (IOI11_ricehub)C++14
100 / 100
29 ms8776 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...