Submission #445176

# Submission time Handle Problem Language Result Execution time Memory
445176 2021-07-16T18:21:20 Z JovanB Rice Hub (IOI11_ricehub) C++17
100 / 100
18 ms 2532 KB
#include "ricehub.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
ll niz[100000];
ll mani;
int N;
 
bool moze(int x){
    ll trencost=0;
    int trenmid, r=x, l=1;
    trenmid = (x+2)/2;
    for(int i=1; i<=x; i++){
        trencost += abs(niz[i]-niz[trenmid]);
    }
    if(trencost <= mani) return true;
    while(r < N){
        r++;
        trenmid++;
        trencost -= niz[trenmid-1]-niz[l];
        trencost += niz[r]-niz[trenmid];
        l++;
        trencost += (niz[trenmid]-niz[trenmid-1])*(trenmid-l);
        trencost -= (niz[trenmid]-niz[trenmid-1])*(r-trenmid);
        if(trencost <= mani) return true;
    }
    return false;
}
 
int besthub(int n, int L, int X[], long long B){
    N = n;
    mani = B;
    for(int i=1; i<=n; i++){
        niz[i] = X[i-1];
    }
    int l=1, r=n;
    int maxres=1;
    while(l <= r){
        int mid = (l+r)/2;
        if(moze(mid)){
            l = mid+1;
            maxres = max(maxres, mid);
        }
        else r = mid-1;
    }
    return maxres;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 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 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 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 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 296 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 296 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 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 17 ms 2460 KB Output is correct
4 Correct 17 ms 2488 KB Output is correct
5 Correct 8 ms 1188 KB Output is correct
6 Correct 8 ms 1148 KB Output is correct
7 Correct 15 ms 2236 KB Output is correct
8 Correct 16 ms 2124 KB Output is correct
9 Correct 9 ms 1076 KB Output is correct
10 Correct 8 ms 1100 KB Output is correct
11 Correct 18 ms 2532 KB Output is correct
12 Correct 17 ms 2484 KB Output is correct
13 Correct 8 ms 1228 KB Output is correct
14 Correct 8 ms 1220 KB Output is correct
15 Correct 13 ms 1868 KB Output is correct
16 Correct 12 ms 1960 KB Output is correct
17 Correct 15 ms 2252 KB Output is correct
18 Correct 15 ms 2228 KB Output is correct
19 Correct 16 ms 2416 KB Output is correct
20 Correct 16 ms 2380 KB Output is correct