#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |