# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
715556 | 2023-03-27T08:09:55 Z | vjudge1 | 쌀 창고 (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; int besthub(int n,int l,int x[],int b){ int cost,mid,ans=0; vector<int> prefixSum(l,0); for(int i=1;i<=n;i++)prefixSum[i] = prefixSum[i-1]+x[i-1]; //for(int i=1;i<=n;i++)cout<<prefixSum[i]<<" "; cout<<endl; for(int st=1;st<=n;st++){ for(int en=st;en<=n;en++){ mid = (st+en)/2; cost = (mid-st)*x[mid]-(prefixSum[mid-1]-prefixSum[st-1]) + (prefixSum[en]-prefixSum[mid])-(en-mid)*x[mid]; if(cost <= b)ans = max(ans,en-st+1); //cout<<st<<" "<<en<<" "<<cost<<endl; } } return ans; }