# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1138148 | MattNattFeczan | 쌀 창고 (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, vector<int>& X, long long B) {
int max_fields = 0;
// Iterate over all possible hub positions (1 to L)
for (int hub = 1; hub <= L; ++hub) {
// Calculate the cost of transporting rice for each subset of rice fields
for (int start = 0; start < R; ++start) {
long long cost = 0;
int count = 0;
for (int end = start; end < R; ++end) {
cost += abs(X[end] - hub);
if (cost > B) {
break;
}
count++;
max_fields = max(max_fields, count);
}
}
}
return max_fields;
}