제출 #1036213

#제출 시각아이디문제언어결과실행 시간메모리
1036213HappyCapybara쌀 창고 (IOI11_ricehub)C++17
49 / 100
10 ms2764 KiB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long

int besthub(int R, int L, int X[], ll B){
  queue<ll> l, r;
  for (int i=0; i<R; i++) r.push(X[i]);

  int bsf = 0, curl = 0, curr = 0, i = 0;
  ll k = 0;
  while (true){
    while ((!r.empty() && ((k+(r.front()-(ll) X[i])) <= B)) || (!l.empty() && !r.empty() && curl && (r.front()-X[i]) < (X[i]-l.front()))){
      while (!r.empty() && ((k+(r.front()-(ll) X[i])) <= B)){
        k += r.front()- (ll) X[i];
        l.push(r.front());
        r.pop();
        curr++;
      }
      if (!l.empty() && !r.empty() && curl && (r.front()-X[i]) < (X[i]-l.front())){
        k += r.front()+l.front()-2ll* (ll) X[i];
        l.pop();
        l.push(r.front());
        r.pop();
        curl--;
        curr++;
      }
    }
    if (k <= B) bsf = max(bsf, curl+curr);
    //cout << i << " " << curl << " " << curr << " " << k << " " << bsf << "\n";
    i++;
    if (i == R) break;
    curl++; curr--;
    k += (ll) (curl-curr) * (ll) (X[i]-X[i-1]);
  }

  return bsf;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...