답안 #520838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520838 2022-01-31T06:52:06 Z Alex_tz307 쌀 창고 (IOI11_ricehub) C++17
100 / 100
37 ms 6424 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

int median = -1;
multiset<int> low, big;
int64_t sum_low, sum_big;

void fix() {
  int m = (low.size() + big.size()) >> 1;
  if ((int)low.size() < m) {
    low.emplace(median);
    sum_low += median;
    median = *big.begin();
    big.erase(big.begin());
    sum_big -= median;
  }
  if ((int)low.size() > m) {
    big.emplace(median);
    sum_big += median;
    median = *--low.end();
    low.erase(--low.end());
    sum_low -= median;
  }
}

void add(int x) {
  if (median == -1) {
    median = x;
    return;
  }
  if (x < median) {
    low.emplace(x);
    sum_low += x;
  } else {
    big.emplace(x);
    sum_big += x;
  }
  fix();
}

void rem(int x) {
  if (x == median) {
    median = *big.begin();
    big.erase(big.begin());
    sum_big -= median;
  } else {
    if (x < median) {
      low.erase(low.find(x));
      sum_low -= x;
    } else {
      big.erase(big.find(x));
      sum_big -= x;
    }
  }
  fix();
}

int64_t cost() {
  return (int64_t)low.size() * median - sum_low + sum_big - (int64_t)big.size() * median;
}

void maxSelf(int &x, int y) {
  if (x < y) {
    x = y;
  }
}

int besthub(int R, int L, int X[], long long B) {
  int ans = 1, l = 0;
  for (int r = 0; r < R; ++r) {
    add(X[r]);
    while (B < cost()) {
      rem(X[l]);
      l += 1;
    }
    maxSelf(ans, r - l + 1);
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 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 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 296 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 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 304 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 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 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 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 448 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 36 ms 6336 KB Output is correct
4 Correct 35 ms 6368 KB Output is correct
5 Correct 14 ms 752 KB Output is correct
6 Correct 12 ms 728 KB Output is correct
7 Correct 37 ms 6156 KB Output is correct
8 Correct 34 ms 6096 KB Output is correct
9 Correct 16 ms 1084 KB Output is correct
10 Correct 16 ms 1048 KB Output is correct
11 Correct 34 ms 6424 KB Output is correct
12 Correct 35 ms 6340 KB Output is correct
13 Correct 14 ms 848 KB Output is correct
14 Correct 14 ms 892 KB Output is correct
15 Correct 32 ms 4944 KB Output is correct
16 Correct 25 ms 4800 KB Output is correct
17 Correct 31 ms 5652 KB Output is correct
18 Correct 31 ms 5684 KB Output is correct
19 Correct 32 ms 6084 KB Output is correct
20 Correct 32 ms 6044 KB Output is correct