Submission #477756

# Submission time Handle Problem Language Result Execution time Memory
477756 2021-10-03T11:39:37 Z Sam_a17 Rice Hub (IOI11_ricehub) C++14
100 / 100
18 ms 1740 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include "ricehub.h"
#include <cstdio>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;

long long prefix[N];
int ans;

int besthub(int n, int maxL, int arr[], long long b){
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr); cout.tie(nullptr);
    for (int i = 0; i < n; i++) {
        if(!i) {
            prefix[i] = arr[i];
        } else {
            prefix[i] = prefix[i - 1] + arr[i];
        }
    }

    int l = 0;
    for(int r = 0; r < n; r++) {
        int mid = (l + r) / 2;
        long long cost = arr[mid] * (mid - l) - arr[mid] * (r - mid) + (prefix[r] - prefix[mid]) - (prefix[mid - 1] - prefix[l - 1]) ;
        while(cost > b) {
            l++, mid = (l + r) / 2, cost = arr[mid] * (mid - l) - arr[mid] * (r - mid) - (prefix[mid - 1] - prefix[l - 1]) + (prefix[r] - prefix[mid]);
        }
        if(cost <= b) {
            ans = max(ans, r - l + 1);
        }
    }

    return ans;
}
# 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 204 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 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 0 ms 204 KB Output is correct
10 Correct 1 ms 304 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 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 308 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 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 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 12 ms 1700 KB Output is correct
4 Correct 12 ms 1740 KB Output is correct
5 Correct 9 ms 1100 KB Output is correct
6 Correct 6 ms 1136 KB Output is correct
7 Correct 16 ms 1628 KB Output is correct
8 Correct 18 ms 1628 KB Output is correct
9 Correct 7 ms 1112 KB Output is correct
10 Correct 6 ms 1100 KB Output is correct
11 Correct 13 ms 1740 KB Output is correct
12 Correct 15 ms 1740 KB Output is correct
13 Correct 6 ms 1100 KB Output is correct
14 Correct 9 ms 1076 KB Output is correct
15 Correct 9 ms 1356 KB Output is correct
16 Correct 10 ms 1364 KB Output is correct
17 Correct 11 ms 1588 KB Output is correct
18 Correct 13 ms 1612 KB Output is correct
19 Correct 13 ms 1612 KB Output is correct
20 Correct 14 ms 1676 KB Output is correct