Submission #410118

# Submission time Handle Problem Language Result Execution time Memory
410118 2021-05-22T03:43:53 Z Leonardo_Paes Rice Hub (IOI11_ricehub) C++17
100 / 100
17 ms 2920 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 1e5+10;

ll sum[maxn];

bool check(int n, int l, const vector<int> &v, ll b, int k){
    for(int i=k-1; i<n; i++){
        int j = i - k + 1;
        int meio = (i + j) >> 1;
        ll val = sum[i] - sum[meio] - v[meio] * (i-meio);
        val += -sum[meio] + (j == 0 ? 0 : sum[j-1]) + v[meio] * (meio - j + 1);
        if(val <= b) return true;
    }
    return false;
}

int besthub(int n, int l, int x[], ll b){
	vector<int> v(n);
	for(int i=0; i<n; i++) v[i] = x[i];   
    sum[0] = v[0];
    for(int i=1; i<n; i++) sum[i] = v[i] + sum[i-1];
    int ini = 1, meio, fim = n, ans = 1;
    while(ini <= fim){
        meio = (ini + fim) >> 1;
        if(check(n, l, v, b, meio)){
            ans = meio;
            ini = meio + 1;
        }
        else fim = meio - 1;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 392 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 4 ms 696 KB Output is correct
3 Correct 16 ms 2864 KB Output is correct
4 Correct 16 ms 2864 KB Output is correct
5 Correct 8 ms 1356 KB Output is correct
6 Correct 8 ms 1332 KB Output is correct
7 Correct 14 ms 2636 KB Output is correct
8 Correct 16 ms 2636 KB Output is correct
9 Correct 8 ms 1356 KB Output is correct
10 Correct 9 ms 1356 KB Output is correct
11 Correct 16 ms 2920 KB Output is correct
12 Correct 17 ms 2832 KB Output is correct
13 Correct 9 ms 1356 KB Output is correct
14 Correct 9 ms 1484 KB Output is correct
15 Correct 12 ms 2236 KB Output is correct
16 Correct 12 ms 2252 KB Output is correct
17 Correct 14 ms 2636 KB Output is correct
18 Correct 14 ms 2572 KB Output is correct
19 Correct 17 ms 2892 KB Output is correct
20 Correct 15 ms 2804 KB Output is correct