답안 #534874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534874 2022-03-09T05:27:40 Z Gurban 쌀 창고 (IOI11_ricehub) C++17
100 / 100
25 ms 2856 KB
#include "bits/stdc++.h"
#include "ricehub.h"
using namespace std;

using ll = long long;

const int maxn=1e5+5;
ll p[maxn],b;
int a[maxn];

bool check(int l,int r){
  int md = (l + r) >> 1;
  ll val = 1ll * a[md] * (md - l);
  if(md-1 >= 0) val -= p[md-1];
  if(l-1 >= 0) val += p[l-1];

  val += p[r] - p[md];
  val -= 1ll * a[md] * (r - md);
  return (val <= b);
}

int besthub(int R, int L, int X[], long long B){

  for(int i = 0;i < R;i++) a[i] = X[i];
  b = B;

  p[0] = X[0];
  for(int i = 1;i < R;i++) p[i] = p[i - 1] + X[i];

  int ans = 1;
  for(int i = 0;i < R;i++){
    int l = 0,r = i - 1,md,jg=i;
    while(l <= r){
      md = (l + r) >> 1;
      if(check(md,i)) jg=md,r=md-1;
      else l=md+1;
    }
    ans = max(ans,i-jg+1);
  }
  return ans;
}

// 5 20 6 1 2 10 12 14 3
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 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 0 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 0 ms 204 KB Output is correct
17 Correct 0 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 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 216 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 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 0 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 1 ms 204 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 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 16 ms 2856 KB Output is correct
4 Correct 16 ms 2852 KB Output is correct
5 Correct 7 ms 1352 KB Output is correct
6 Correct 8 ms 1320 KB Output is correct
7 Correct 18 ms 2648 KB Output is correct
8 Correct 15 ms 2636 KB Output is correct
9 Correct 9 ms 1352 KB Output is correct
10 Correct 9 ms 1316 KB Output is correct
11 Correct 19 ms 2804 KB Output is correct
12 Correct 17 ms 2852 KB Output is correct
13 Correct 8 ms 1368 KB Output is correct
14 Correct 8 ms 1484 KB Output is correct
15 Correct 12 ms 2248 KB Output is correct
16 Correct 13 ms 2124 KB Output is correct
17 Correct 15 ms 2596 KB Output is correct
18 Correct 16 ms 2596 KB Output is correct
19 Correct 25 ms 2756 KB Output is correct
20 Correct 18 ms 2756 KB Output is correct