Submission #556267

# Submission time Handle Problem Language Result Execution time Memory
556267 2022-05-02T16:54:07 Z Dan4Life Rice Hub (IOI11_ricehub) C++17
0 / 100
4 ms 468 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll pref[100010];

ll sum(int i, int j){ return pref[j+1]-pref[i]; }

int besthub(int n, int m, int a[], ll k)
{
    pref[0] = 0;
    for(int i = 0; i < n; i++)
        pref[i+1] = pref[i]+(ll)a[i];
    int l = 1, r = n;
    while(l<r){
        int mid = (l+r+1)/2; ll mn = (ll)4e18;
        for(int i = 0; i <= n-mid; i++){
            int j = i+mid-1; int med = (i+j)/2;
            ll sum1 = (ll)a[med]*(med-i+1)-sum(i,med);
            ll sum2 = sum1+sum(med+1,j)-a[med]*(j-med);
            mn = min(mn, sum1+sum2);
            if(med-1>=i){
                med--;
                sum1 = (ll)a[med]*(med-i+1)-sum(i,med);
                sum2 = sum1+sum(med+1,j)-a[med]*(j-med);
                mn = min(mn, sum1+sum2), med++;
            }
            if(med+1<=j){
                med++;
                sum1 = (ll)a[med]*(med-i+1)-sum(i,med);
                sum2 = sum1+sum(med+1,j)-a[med]*(j-med);
                mn = min(mn, sum1+sum2), med--;
            }
        }
        if(mn<=k) l=mid;
        else r = mid-1;
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -