Submission #104430

# Submission time Handle Problem Language Result Execution time Memory
104430 2019-04-06T19:24:28 Z dfistric Rice Hub (IOI11_ricehub) C++14
100 / 100
33 ms 1792 KB
#include <bits/stdc++.h>
#include "ricehub.h"

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

int besthub(int n, int L, int arr[], ll B) {
    int r = 1, m = 0;
    int a = 1, b = 0;
    ll sum = 0;
    int ma = 0;
    REP(l, n) {
        if ((r + l) / 2 > m) {
            sum = sum - b * (arr[m + 1] - arr[m]) + a * (arr[m + 1] - arr[m]);
            a++;
            b--;
            m++;    
        }

        while (r < n) {
            //cout << l << " " << r << " " << m << " " << a << " " << b << " " << sum << endl;
            int rr = r + 1, aa = a, bb = b + 1;
            int mm = (rr + l) / 2;
            ll sum2 = sum + (arr[r] - arr[m]);
            
            if (mm > m) {
                sum2 = sum2 - bb * (arr[mm] - arr[m]) + aa * (arr[mm] - arr[m]);
                aa++;
                bb--;
            }

            if (sum2 <= B) {
                sum = sum2, r = rr, a = aa, b = bb, m = mm;
            } else {
                break;
            }
        }
        //cout << l << " " << r << " " << m << " " << a << " " << b << " " << sum << endl << endl;
        ma = max(ma, r - l);
        a--, sum -= (arr[m] - arr[l]);
    }

    return ma;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 300 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 300 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 416 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 412 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 416 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 25 ms 768 KB Output is correct
4 Correct 19 ms 768 KB Output is correct
5 Correct 8 ms 484 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 19 ms 1508 KB Output is correct
8 Correct 13 ms 1408 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 10 ms 800 KB Output is correct
11 Correct 18 ms 1792 KB Output is correct
12 Correct 24 ms 1776 KB Output is correct
13 Correct 10 ms 896 KB Output is correct
14 Correct 9 ms 916 KB Output is correct
15 Correct 16 ms 1420 KB Output is correct
16 Correct 15 ms 1404 KB Output is correct
17 Correct 17 ms 1536 KB Output is correct
18 Correct 16 ms 1536 KB Output is correct
19 Correct 17 ms 1664 KB Output is correct
20 Correct 33 ms 1724 KB Output is correct