답안 #409577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409577 2021-05-21T05:46:35 Z 600Mihnea 쌀 창고 (IOI11_ricehub) C++17
0 / 100
5 ms 460 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

typedef long long ll;

const int N = 100000 + 7;
int n, len, x[N];
ll b, s_first, s_second;

deque<int> first, second;

ll compute() {
  int x;
  if ((int) second.size() == (int) first.size()) {
    x = second.front();
  } else {
    x = first.back();
  }
  ll cost = s_second - s_first;
  cost += (ll) x * (int) first.size();
  cost -= (ll) x * (int) second.size();
  return cost;
}

int besthub(int r, int dim, int rice_fields[], ll gold_coins) {
  n = r;
  len = dim;
  for (int i = 1; i <= n; i++) {
    x[i] = rice_fields[i - 1];
  }
  b = gold_coins;
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    second.push_back(x[i]);
    s_second += x[i];
    if ((int) second.size() > (int) first.size()) {
      s_second -= second.front();
      s_first += second.front();
      first.push_back(second.front());
      second.pop_front();
    }
    while (compute() > b) {
      if (first.empty()) {
        second.pop_front();
      } else {
        first.pop_front();
      }
      if ((int) second.size() > (int) first.size()) {
        s_second -= second.front();
        s_first += second.front();
        first.push_back(second.front());
        second.pop_front();
      }
    }
    sol = max(sol, (int) first.size() + (int) second.size());
  }
  return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 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 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -