Submission #235565

# Submission time Handle Problem Language Result Execution time Memory
235565 2020-05-28T14:38:51 Z Toirov_Sadi Rice Hub (IOI11_ricehub) C++17
100 / 100
26 ms 2560 KB
#include<bits/stdc++.h>
#include "ricehub.h"

using namespace std;

int besthub(int n, int L, int X[], long long B){

    vector<long long> p(n, 0);
    for(int i = 0; i < n; i ++){
        if(i > 0) p[i] = p[i - 1];
        p[i] += X[i];
    }
    int l = 0, r = n;
    while(l < r){
        int m = ((l + r) / 2) + 1;

        /// can m ?
        bool can = false;
        for(int i = 0; i + m < n; i ++){
            int l1 = i, r1 = i + m;
            int mid = (l1 + r1) / 2;
            int x = (m + 2) / 2;
            int y = (m + 1) - ((m + 2) / 2);
            long long cur = x * 1ll * X[mid] - (p[mid] - (l1 == 0 ? 0 : p[l1 - 1]));
            cur += (p[r1] - p[mid]) - y * 1ll * X[mid];
            if(cur <= B) can = true;
        }

        if(can == true){
            l = m;
        }
        else{
            r = m - 1;
        }
    }
    return l + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 128 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 416 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 22 ms 2560 KB Output is correct
4 Correct 20 ms 2560 KB Output is correct
5 Correct 14 ms 1280 KB Output is correct
6 Correct 14 ms 1280 KB Output is correct
7 Correct 26 ms 2304 KB Output is correct
8 Correct 20 ms 2304 KB Output is correct
9 Correct 15 ms 1280 KB Output is correct
10 Correct 13 ms 1280 KB Output is correct
11 Correct 22 ms 2560 KB Output is correct
12 Correct 22 ms 2560 KB Output is correct
13 Correct 15 ms 1280 KB Output is correct
14 Correct 15 ms 1280 KB Output is correct
15 Correct 19 ms 2048 KB Output is correct
16 Correct 20 ms 2048 KB Output is correct
17 Correct 20 ms 2432 KB Output is correct
18 Correct 19 ms 2304 KB Output is correct
19 Correct 21 ms 2432 KB Output is correct
20 Correct 21 ms 2432 KB Output is correct