Submission #757440

# Submission time Handle Problem Language Result Execution time Memory
757440 2023-06-13T07:43:57 Z joelgun14 Rice Hub (IOI11_ricehub) C++17
0 / 100
100 ms 736 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define ub upper_bound
#define lb lower_bound
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
  // for every median, calculate maximum res di kiri dan di kanan
  // calculate yg exactly maximum res berapa
  // rlog^2r
  int a[R + 1];
  a[0] = 0;
  for(int i = 1; i <= R; ++i)
    a[i] = X[i - 1];
  long long pref[R + 1];
  pref[0] = 0;
  for(int i = 1; i <= R; ++i)
    pref[i] = pref[i - 1] + a[i];
  int ans = 1;
  for(int i = 1; i <= R; ++i) {
    long long l = 1, r = L;
    while(l <= r) {
      int mid = (l + r) / 2;
      // cek klo cost ambil yg < mid brp, yg tepat jarak mid ada berapa
      // cek lower dlu
      int idx1 = ub(a, a + R + 1, a[i] - mid) - a, cntmid = ub(a, a + R + 1, a[i] - mid) - lb(a, a + R + 1, a[i] - mid);
      int idx2 = lb(a, a + R + 1, a[i] + mid) - a - 1;
      cntmid += ub(a, a + R + 1, a[i] + mid) - lb(a, a + R + 1, a[i] + mid);
      // cari prefsum dr idx1 dan idx2
      long long cost = 1ll * (i - idx1 + 1) * a[i] - (pref[i] - (idx1 - 1 >= 0 ? pref[idx1 - 1] : 0));
      cost += (pref[idx2] - pref[i - 1]) - 1ll * (idx2 - i + 1);
      //cout << i << "  " << idx1 << " " << idx2 << " " << cost << " " << cntmid << endl;
      if(cost > B) {
        r = mid - 1;
        continue;
      }
      else {
        ans = max((long long)ans, abs(idx2 - idx1) + 1 + min((B - cost) / mid, (long long)cntmid));
        l = mid + 1;
      }
    }
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 736 KB Output isn't correct
2 Halted 0 ms 0 KB -