Submission #335962

# Submission time Handle Problem Language Result Execution time Memory
335962 2020-12-14T11:44:11 Z aryan12 Rice Hub (IOI11_ricehub) C++17
0 / 100
4 ms 748 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

int besthub(int r, int l, int x[], long long b) {
    long long pre[r + 1], suf[r + 1];
    pre[1] = 0;
    for(long long i = 2; i <= r; i++) {
        pre[i] = pre[i - 1] + x[i];
    }
    suf[r] = 0;
    for(long long i = r - 1; i >= 1; i--) {
        suf[i] = suf[i + 1] + x[i];
    }
    /*for(long long i = 1; i <= r; i++) {
        cout << pre[i] << " ";
    }
    cout << endl;
    for(long long i = r; i > 0; i--) {
        cout << suf[i] << " ";
    }
    cout << endl;*/
    long long ans = 1;
    for(long long i = 2; i <= r; i++) {
        long long left = 1, right = i, best = r;
        long long mid;
        while(left <= right) {
            mid = (left + right) / 2;
            long long FieldSituated = (mid + i) / 2, cost = 0;
            /*for(long long j = mid; j <= i; j++) {
                cost += (abs(x[j] - x[FieldSituated]));
            }*/
            cost += suf[FieldSituated];
            if(i != r) {
                long long Distance = x[i + 1] - x[FieldSituated];
                cost -= Distance * (r - i);
                cost -= suf[i + 1];
            }
            //cout << "cost before prefix = " << cost << ", ";
            cost += pre[FieldSituated];
            if(mid != 1) {
                long long Distance = x[FieldSituated] - x[mid - 1];
                cost -= Distance * (mid - 1);
                cost -= pre[mid - 1];
            }
            //cout << "cost = " << cost << ", mid = " << mid << ", i = " << i << ", FieldSituated = " << FieldSituated << endl;
            if(cost <= b) {
                right = mid - 1;
                best = mid;
            }
            else {
                left = mid + 1;
            }
        }
       // cout << i << " " << best << endl;
        ans = max(ans, i - best + 1);
    }
    int lol = ans;
    return lol;
}
/*
int main() {
    //cout << "Input the number of rice fields" << endl;
    int r;
    cin >> r;
    //cout << "Input the maximum coordinate" << endl;
    int l;
    cin >> l;
    //cout << "Input r numbers, denoting the rice fields" << endl;
    int x[r + 1];
    for(int i = 1; i <= r; i++) {
        cin >> x[i];
    }
    //cout << "Input the budget" << endl;
    int b;
    cin >> b;
    cout << besthub(r, l, x, b) << endl;
}

*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -