제출 #488980

#제출 시각아이디문제언어결과실행 시간메모리
488980fun_dayRice Hub (IOI11_ricehub)C++14
100 / 100
14 ms2384 KiB
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int besthub(int R , int L , int X[] , long long B){
  vector<long long> pref(R);
  for(int i = 0 ; i < R ; i++){
    if(i == 0) pref[i] = (long long) X[i];
    else pref[i] = pref[i - 1] + (long long) X[i];
  }
  int l = 0;
  int best = 0;
  for(int i = 0 ; i < R ; i++){
    int mid = l + (i - l) / 2;
    int cur = i - mid , here = mid - l;
    long long sum = (pref[i] - pref[mid]) - (long long) X[mid] * cur;
    long long s = 0;
    if(mid > 0) s = (long long) X[mid] * here - (pref[mid - 1] - (l > 0 ? pref[l - 1] : 0));
    if(s + sum <= B){
      best = max(best , cur + here);
    }
    else{
      l++; i--;
    }
  }
  return best + 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...