Submission #584665

# Submission time Handle Problem Language Result Execution time Memory
584665 2022-06-27T18:45:09 Z sofijavelkovska Rice Hub (IOI11_ricehub) C++14
100 / 100
13 ms 1416 KB
#include <bits/stdc++.h>
using namespace std;

int besthub(int n, int p, int a[], long long k)
{
    long long prefix[n];
    for (long long i=0; i<n; i++)
    {
        if (i==0)
            prefix[i]=a[i];
        else
            prefix[i]=prefix[i-1]+a[i];
    }
    long long l=0, r=0, m;
    long long maxrice=0;
    while (r<n)
    {
        m=(r+l)/2;
        long long distanceright, distanceleft;
        distanceright=prefix[r]-prefix[m];
        if (l!=0)
            distanceleft=prefix[m-1]-prefix[l-1];
        else if (m!=0)
            distanceleft=prefix[m-1];
        else
            distanceleft=0;
        long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m));
        if (budget<=k)
        {
            maxrice=max(maxrice, r-l+1);
            r=r+1;
        }
        else
        {
            r=r+1;
            l=l+1;
        }
    }
    return maxrice;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 11 ms 1408 KB Output is correct
4 Correct 12 ms 1364 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 10 ms 1364 KB Output is correct
8 Correct 10 ms 1416 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 11 ms 1408 KB Output is correct
12 Correct 13 ms 1416 KB Output is correct
13 Correct 5 ms 896 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 8 ms 1108 KB Output is correct
16 Correct 10 ms 1108 KB Output is correct
17 Correct 9 ms 1236 KB Output is correct
18 Correct 10 ms 1236 KB Output is correct
19 Correct 10 ms 1364 KB Output is correct
20 Correct 10 ms 1364 KB Output is correct