Submission #584652

# Submission time Handle Problem Language Result Execution time Memory
584652 2022-06-27T18:30:46 Z teki Rice Hub (IOI11_ricehub) C++11
100 / 100
14 ms 1456 KB
#include <bits/stdc++.h>
#include "ricehub.h"

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
const ll MN = 1000000007;

using namespace std;

int besthub(int n, int l, int poz[], ll b) {
    ll prefSuma[n];
    MS(prefSuma,0);

    for (ll i = 0; i<n; i++) {
        prefSuma[i] = poz[i];
        if (i != 0) prefSuma[i] += prefSuma[i-1];
    }

    ll from = 0;
    ll res = 0;

    for (ll to = 0; to<n; to++) {
        ll mid = (from+to)/2;

        ll levoS = mid-from;
        ll desnoS = to-mid;

        ll necBud = 0;

        if (from < mid) {
            necBud += levoS*poz[mid];
            necBud -= prefSuma[mid-1];
            if (from != 0) necBud += prefSuma[from-1];
        }

        if (to > mid) {
            necBud += prefSuma[to];
            necBud -= prefSuma[mid];
            necBud -= desnoS*poz[mid];
        }

        if (necBud > b) from++;
        else res = max(res,to-from+1);
    }

    return res;

}

//int main()
//{
//    #if LOCAL_DEBUG
//        fstream cin("in.txt");
//    #endif
//
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
//
//    int niz[] = {1,2,10,12,14};
//
//    cout<<besthub(5,20,niz,6)<<endl;
//
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 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 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 312 KB Output is correct
17 Correct 0 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 0 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 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 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 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 3 ms 468 KB Output is correct
3 Correct 11 ms 1364 KB Output is correct
4 Correct 10 ms 1392 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 14 ms 1436 KB Output is correct
8 Correct 9 ms 1364 KB Output is correct
9 Correct 6 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 11 ms 1364 KB Output is correct
12 Correct 11 ms 1456 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 8 ms 1108 KB Output is correct
16 Correct 8 ms 1176 KB Output is correct
17 Correct 10 ms 1280 KB Output is correct
18 Correct 10 ms 1244 KB Output is correct
19 Correct 10 ms 1364 KB Output is correct
20 Correct 11 ms 1416 KB Output is correct