Submission #684346

# Submission time Handle Problem Language Result Execution time Memory
684346 2023-01-21T00:06:54 Z speedyArda Rice Hub (IOI11_ricehub) C++14
0 / 100
3 ms 1108 KB
#include "ricehub.h"
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B)
{

  ll pref[R];
  ll Big[R];
  for(int i = 0; i < R; i++)
  {
      if(i > 0)
        pref[i] = pref[i - 1];
      pref[i] += X[i];
      Big[i] = X[i];
  }

  int left = 1, right = R;
  int ans = 0;
  while(left <= right)
  {
    int m = (left + right) / 2; // We are controlling whether we can get m rices. We use binary search because rice count is monotonic. For example, we can get 6 rices, if we can get 7 rices.
    //int mid = 1;
    bool valid = false;
    ll price = 0;
    for(int i = 0; i < R; i++)
    {
      int mid = i + m / 2;
      ll price = Big[mid] * (mid - i + 1) - (pref[mid] - pref[i - 1]);
      price += (pref[i + m - 1] - pref[mid - 1]) - Big[mid] * (i + m - mid);
      if(price <= B)
        valid = true;
    }

    

    if(valid) {
      left = m + 1;
      ans = m;
    }
    else
      right = m - 1;

  }
  return ans;
}



 

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:26:8: warning: unused variable 'price' [-Wunused-variable]
   26 |     ll price = 0;
      |        ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -