Submission #914773

# Submission time Handle Problem Language Result Execution time Memory
914773 2024-01-22T16:18:33 Z DucNguyen2007 Rice Hub (IOI11_ricehub) C++14
100 / 100
11 ms 3672 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxN=1e5+5;
ll sum[maxN+1];
int a[maxN+1];
ll get(ll l,ll r)
{
    if(l==0)
    {
        return sum[r];
    }
    else return sum[r]-sum[l-1];
}
bool check(ll len,int n,ll B,int a[])
{
    ll l=0,r=len-1;
    while(r<n)
    {
        ll p=(l+r)/2;
        ll cur=(p-l+1)*a[p]-get(l,p)+get(p,r)-(r-p+1)*a[p];
        if(cur<=B)
        {
            return true;
        }
        l++;
        r++;
    }
    return false;
}
ll besthub(int n,int L,int a[],ll B)
{
    sum[0]=a[0];
    for(int i=1;i<n;i++)
    {
        sum[i]=sum[i-1]+a[i];
    }
    ll res,l=1,r=n;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(check(mid,n,B,a))
        {
            res=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return res;
}

/*5 20 6
1 2 10 12 14*/

Compilation message

ricehub.cpp: In function 'long long int besthub(int, int, int*, long long int)':
ricehub.cpp:49:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |     return res;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2492 KB Output is correct
2 Correct 1 ms 2500 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2500 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2496 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2500 KB Output is correct
9 Correct 1 ms 2756 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2508 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 9 ms 3160 KB Output is correct
4 Correct 11 ms 3420 KB Output is correct
5 Correct 5 ms 2652 KB Output is correct
6 Correct 5 ms 2652 KB Output is correct
7 Correct 8 ms 3164 KB Output is correct
8 Correct 8 ms 3160 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 5 ms 2648 KB Output is correct
11 Correct 9 ms 3420 KB Output is correct
12 Correct 9 ms 3416 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 5 ms 2868 KB Output is correct
15 Correct 7 ms 3164 KB Output is correct
16 Correct 7 ms 3160 KB Output is correct
17 Correct 8 ms 3420 KB Output is correct
18 Correct 8 ms 3420 KB Output is correct
19 Correct 9 ms 3672 KB Output is correct
20 Correct 9 ms 3420 KB Output is correct