제출 #392620

#제출 시각아이디문제언어결과실행 시간메모리
392620ritul_kr_singh쌀 창고 (IOI11_ricehub)C++17
100 / 100
30 ms2520 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #include "ricehub.h" int besthub(int n, int L, int X[], ll B){ ll pre[n+1] = {0}; for(int i=0; i<n; ++i) pre[i+1] = (ll)X[i] + pre[i]; int ans = 1; for(int i=1; i<=n; ++i){ int low = i, high = n; while(low < high){ int mid = (low + high) / 2; ++mid; int mx = (mid + i) / 2; ll cost = 0, pos = X[mx - 1]; if(i < mx){ ll s = pre[mx-1] - pre[i-1]; cost += pos * (mx - i) - s; } if(mx < mid){ ll s = pre[mid] - pre[mx]; cost += s - pos * (mid - mx); } if(cost <= B) low = mid; else high = mid - 1; } ans = max(ans, low - i + 1); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...