# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
884213 | 2023-12-06T18:39:45 Z | TahirAliyev | 쌀 창고 (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<ll, ll> #define oo 1e18 #define all(v) v.begin(), v.end() const int MAX = 1e5 + 5; int n, L, B; int arr[MAX]; int pre[MAX]; signed besthub(int R, signed L, signed X[], long long B) { cin >> n >> L >> B; for(int i = 1; i <= n; i++){ cin >> arr[i]; pre[i] = pre[i - 1] + arr[i]; } int l = 1, r = n; int ans = 1; while(l <= r){ int len = (l + r) / 2; int cost = 0; for(int s = 1; s <= n - len + 1; s++){ int f = s + len - 1; int med = (s + f) / 2; cost = min(cost, (arr[med] * (med - s)) - (pre[med] - pre[s - 1]) + (arr[med] * (f - med)) - (pre[f] - pre[med])); } if(cost <= B){ ans = len; l = len + 1; } else{ r = len - 1; } } return ans; }