Submission #522600

# Submission time Handle Problem Language Result Execution time Memory
522600 2022-02-05T09:16:19 Z ddy888 Rice Hub (IOI11_ricehub) C++17
68 / 100
15 ms 4044 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#include "ricehub.h"

int N, M, K, ans;
int cnt[100010], pre[100010];
vector<int> A;

int sum(int lx, int rx) {
    return pre[rx] - pre[lx - 1];
}

bool check(int lx, int rx) {
    int x = A[(rx + lx + 1) / 2];
    auto it1 = lower_bound(A.begin() + lx, A.begin() + rx + 1, x);
    auto it2 = upper_bound(A.begin() + lx, A.begin() + rx + 1, x);
    int small = 0, big = 0;
    if (it1 != A.begin()) --it1, small = (it1 - A.begin()) - lx + 1;
    if (it2 != A.end()) big = rx - (it2 - A.begin()) + 1;
    int cost = x * (small - big) - (sum(lx, (it1 - A.begin())) - sum((it2 - A.begin()), rx));
    return cost <= K;
}

int besthub(int R, int L, int X[], long long B)
{
    N = R; M = L; K = B;
    A.resize(N + 1);
    for (int i = 1; i <= N; ++i) {
        A[i] = X[i - 1];
        ++cnt[A[i]];
        pre[i] = pre[i - 1] + A[i];
    }
    int rx = 1;
    for (int i = 1; i <= N; ++i) {
        while (rx <= N && check(i, rx)) {
            ans = max(ans, rx - i + 1);
            ++rx;
        }
    }
    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 0 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 332 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 308 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 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 3888 KB Output is correct
4 Correct 2 ms 3916 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 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 300 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 2732 KB Output is correct
20 Correct 2 ms 2736 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 2 ms 312 KB Output is correct
23 Correct 1 ms 420 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 4044 KB Output is correct
26 Correct 3 ms 4044 KB Output is correct
27 Correct 2 ms 2764 KB Output is correct
28 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 4 ms 1020 KB Output is correct
3 Runtime error 15 ms 3788 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -