Submission #615749

# Submission time Handle Problem Language Result Execution time Memory
615749 2022-07-31T12:18:53 Z Minindu2006 Rice Hub (IOI11_ricehub) C++14
100 / 100
14 ms 3120 KB
#include "ricehub.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> pref, arr;
ll getSum(int a, int b)
{
  return pref[b] - pref[a - 1];
}
int besthub(int R, int L, int X[], long long B)
{
  pref.resize(R + 1, 0);
  arr.resize(R + 1);
  for(int i=1;i<=R;i++)
    pref[i] += pref[i - 1] + X[i - 1], arr[i] = X[i - 1];
  int ans = -1;
  // for(int i=1;i<=R;i++)
  // {
  //   for(int j=i;j<=R;j++)
  //   {
  //     int mid = (i + j) / 2;
  //     ll cur = (arr[mid] * (mid - i) - getSum(i, mid - 1)) + (getSum(mid + 1, j) - arr[mid] * (j - mid));
  //      cout << cur << '\n';
  //     if(cur <= B)
  //       ans = max(j - i + 1, ans);
  //   }
  // }
  int i = 1, j = 1;
  while(R - j >= 0)
  {
    int mid = (i + j) / 2;
    ll cur = (arr[mid] * (mid - i) - getSum(i, mid - 1)) + (getSum(mid + 1, j) - arr[mid] * (j - mid));
    if(cur <= B)
      ans = max(j - i + 1, ans), j++;
    else
      i++;
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 12 ms 2260 KB Output is correct
4 Correct 12 ms 2216 KB Output is correct
5 Correct 5 ms 1236 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 14 ms 2280 KB Output is correct
8 Correct 12 ms 2260 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 12 ms 2260 KB Output is correct
12 Correct 13 ms 2260 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 5 ms 1248 KB Output is correct
15 Correct 9 ms 1748 KB Output is correct
16 Correct 9 ms 1748 KB Output is correct
17 Correct 12 ms 2900 KB Output is correct
18 Correct 11 ms 2900 KB Output is correct
19 Correct 12 ms 3120 KB Output is correct
20 Correct 12 ms 3112 KB Output is correct