Submission #1031351

#TimeUsernameProblemLanguageResultExecution timeMemory
1031351deeraRice Hub (IOI11_ricehub)C++14
0 / 100
2 ms604 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int X[], long long B) {
    int max_rice = 0;
    for (int i = 0; i < R; i++) {
        int c = X[i];
        int l = i, r = i + 1;
        int q = B;
        int t = 0;


        if (l >= 0 && r <= R - 1) {
            int l_cost = abs(c - X[l]);
            int r_cost = abs(c - X[r]);

            if (min(l_cost, r_cost) > q) {
                max_rice = max(t, max_rice);
                continue;
            }

            if (l_cost <= r_cost) {
                t++;
                l--;
                q -= l_cost;
            } else {
                t++;
                r++;
                q -= r_cost;
            }
        } else if (r <= R - 1) { 
            // can't go left
            int r_cost = abs(c - X[r]);
            if (r_cost > q) {
                max_rice = max(t, max_rice);
                continue;
            }

            t++;
            r++;
            q -= r_cost;
        } else if (l >= 0) {
            int l_cost = abs(c - X[l]);
            if (l_cost > q) {
                max_rice = max(t, max_rice);
                continue;
            }

            t++;
            l--;
            q -= l_cost;
        } else {
            max_rice = max(t, max_rice);
            continue;
        }
    }

    return max_rice;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...