Submission #1138149

#TimeUsernameProblemLanguageResultExecution timeMemory
1138149MattNattFeczanRice Hub (IOI11_ricehub)C++20
42 / 100
1093 ms428 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...