Submission #348394

#TimeUsernameProblemLanguageResultExecution timeMemory
348394idk321Rice Hub (IOI11_ricehub)C++11
32 / 100
16 ms1920 KiB
#include "ricehub.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int besthub(int n, int l, int x[], long long money)
{

  int a = 0;
  int b = 0;
  ll cost = 0;
  int best = 0;
  while (b + 1 < n && cost + x[(b + 1)] - x[0] <= money)
  {
    cost += x[(b + 1)] - x[0];
    b++;
  }
  int left = 0;
  int right = b;
  best = max(best, b - a + 1);
  //cout << "oj " << cost << endl;
  for (int i = 1; i < n; i++)
  {
        cost -= (ll) right * (x[i] - x[i - 1]);
        left++;
        cost += (ll) left * (x[i] - x[i - 1]);
        right--;
        while(cost > money)
        {
            cost -= x[i] - x[a];
            a++;
            left--;
        }
        while(b + 1 < n && x[b + 1] - x[i] + cost < money)
        {
            cost += x[b + 1] - x[i];
            b++;
            right++;
        }
        while (b + 1 < n && x[i] - x[a] > x[b + 1] - x[i])
        {
            cost -= x[i] - x[a];
            a++;
            left--;
            cost += x[b + 1] - x[i];
            b++;
            right++;
        }

        //cout << "oj " << a << " " << b << " " << cost << endl;
        best = max(best, b - a + 1);
  }
  return best;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...