답안 #522598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522598 2022-02-05T09:14:37 Z ddy888 쌀 창고 (IOI11_ricehub) C++17
0 / 100
3 ms 964 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)) ++rx;
        if (rx > N) break;
        ans = max(ans, rx - i + 1);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 964 KB Output isn't correct
2 Halted 0 ms 0 KB -