# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1027679 | 2024-07-19T08:59:54 Z | vjudge1 | 쌀 창고 (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; const long long MAX=1e5+10; long long pref[MAX]; vector<long long> niza; long long budget; bool can(long long x) { for(long long i=0; i<=niza.size()-x; i++) { long long idx=(i+i+x)/2; long long pt=niza[idx]; long long l=pt*(idx-i)-(pref[idx]-pref[i]+niza[i]-niza[idx]); long long r=(pref[i+x-1]-pref[idx]+niza[idx])-pt*(i+x-idx); //cout<<"for: "<<i+1<<" "<<i+x<<" lr is: "<<l<<" "<<r<<" "<<budget<<endl; if(l+r<=budget)return true; } return false; } long long besthub(long long R, long long L, long long X[], long long B) { budget=B; for(long long i=0; i<R; i++)niza.push_back(X[i]); pref[0]=X[0]; for(long long i=1; i<R; i++)pref[i]=pref[i-1]+X[i]; long long b=0; long long e=R; long long res=0; while(b<=e) { long long mid=(b+e)/2; if(can(mid)) { res=mid; b=mid+1; } else e=mid-1; } return res; } /*int main() { int R,L,B; cin>>R>>L>>B; int X[R]; budget=B; for(int i=0; i<R; i++)cin>>X[i]; for(int i=0; i<R; i++)niza.push_back(X[i]); pref[0]=X[0]; for(int i=1; i<R; i++)pref[i]=pref[i-1]+X[i]; int b=0; int e=R; int res=0; while(b<=e) { int mid=(b+e)/2; cout<<"mid: "<<mid<<endl; if(can(mid)) { res=mid; b=mid+1; } else e=mid-1; } cout<<res<<endl; return 0; } 5 20 6 1 2 10 12 14*/