Submission #744171

# Submission time Handle Problem Language Result Execution time Memory
744171 2023-05-18T08:54:33 Z vjudge1 Rice Hub (IOI11_ricehub) C++17
0 / 100
3 ms 560 KB
#include "ricehub.h"

int besthub(int R, int L, int X[], long long B)
{
    long long qs[R+1];
    qs[0] = 0;
    long long ans;
    for(int i=1;i<=R;++i)
    {
        qs[i] = qs[i-1]+X[i-1];
    }
    long long l = 1,r = R;
    while(l <= r)
    {
        long long mid = (l+r)/2;
        bool can = false;
        for(int med = (mid+1)/2;med <= r-mid/2;++med)
        {
            long long sumLeft = qs[med-(mid%2==1)]-qs[med-mid/2+(mid%2==0)];
            long long sumRight = qs[med+mid/2]-qs[med+1];
            long long cost = sumRight - sumLeft;
            if(cost <= B)
            {
                can = true;
                break;
            }
        }
        if(can)
        {
            ans = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:35:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |     return ans;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 560 KB Output isn't correct
2 Halted 0 ms 0 KB -