# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
485234 | chungdinh | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>
using namespace std;
#define endl "\n"
#define cntbit(x) __builtin_popcount(x)
#define on(b, x) (b & (1 << x))
#define all(x) x.begin(), x.end()
#define gcd __gcd
#define ll long long
#define ii pair<int, int>
#define cost(l, r) a[r] - a[l]
const int N = 3e3 + 5;
const ll MOD = 998244353;
const int iINF = 1e9;
const ll INF = 1e18;
int n;
ll l, b;
ll a[N];
int besthub(int n, ll l, ll a[N], ll b) {
int res = 0;
for (int i = 0; i < n; i++) {
int l = i - 1, r = i + 1;
int subres = 0;
ll left = b;
while (l >= 0 || r <= n - 1) {
if (l < 0) {
if (cost(i, r) > left) break;
subres++;
left -= cost(i, r);
r++;
} else if (r > n - 1) {
if (cost(l, i) > left) break;
subres++;
left -= cost(l, i);
l--;
} else {
ll tt = min(cost(l, i), cost(i, r));
if (tt > left) break;
if (cost(l, i) < cost(i, r)) {
left -= cost(l, i);
l--;
} else {
left -= cost(i, r);
r++;
}
subres++;
}
}
res = max(res, subres + 1);
}
return res;
}
/*
int main() {
#ifdef CHUNGDINH
freopen("main.inp", "r", stdin);
#endif
scanf("%d%lld%lld",&n,&l,&b);
for (int i = 0; i < n; i++) scanf("%lld", a + i);
printf("%d", besthub(n, l, a, b));
}*/