Submission #1287546

#TimeUsernameProblemLanguageResultExecution timeMemory
1287546repmannRice Hub (IOI11_ricehub)C++20
17 / 100
2 ms588 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int besthub(int N, int M, int X[], ll K)
{
  int sol = 0;
  ll temp = 0;
  for(int i = 0, l = 0, r = 0; i < N; i++)
  {
    if(i)
    {
      while(((r + 1) < N) && (X[r + 1] <= X[i]))
      {
        temp += X[r + 1] - X[i - 1];
        r++;
      }
      temp += ((i - l) - (r - i + 1LL)) * (X[i] - X[i - 1]);
    }
    while((l < i) && (temp > K))
    {
      temp -= X[i] - X[l];
      l++;
    }
    while(((r + 1) < N) && ((temp + X[r + 1] - X[i]) <= K))
    {
      temp += X[r + 1] - X[i];
      r++;
    }
    while((l < i) && ((r + 1) < N) && ((X[i] - X[l]) >= (X[r + 1] - X[i])))
    {
      if(temp <= K) sol = max(r - l + 1, sol);
      temp -= X[i] - X[l];
      l++;
      while(((r + 1) < N) && ((temp + X[r + 1] - X[i]) <= K))
      {
        temp += X[r + 1] - X[i];
        r++;
      }
    }
    if(temp <= K) sol = max(r - l + 1, sol);
  }
  return sol;
}
//int main()
//{
//  int n, m;
//  ll k;
//  cin >> n >> m >> k;
//  int x[n];
//  for(int i = 0; i < n; i++) cin >> x[i];
//  cout << besthub(n, m, x, k) << '\n';
//  return 0;
//}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...