Submission #359254

# Submission time Handle Problem Language Result Execution time Memory
359254 2021-01-26T14:20:13 Z Pety Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"


using namespace std;

vector<int> v;
vector<long long> sum;

int cost (int l, int r) {
  int mij = (l + r) / 2;
  return 1ll * v[mij] * (mij - l + 1) - (sum[mij] - sum[l - 1]) + (sum[r] - sum[mij - 1]) - 1ll * (r - mij + 1) * v[mij];
}

int besthub (int n, int l, vector<int>x, long long b) {
  sum.resize(x.size());
  v = x;
  for (int i = 0; i < x.size(); i++)
    sum[i] = (i ? sum[i - 1] + x[i] : x[i]);
  int sol = 0;
  for (int i = 0; i < n; i++) {
    int st = i, dr = n - 1, ans = 0;
    while (st <= dr) {
      int mij = (st + dr) / 2;
      if (cost(st, mij) <= b) {
        ans = mij;
        st = mij + 1;
      }
      else
        dr = mij - 1;
    }
    sol = max(sol, ans - i + 1);
  }
  return sol;
}

/*int main () {
  cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
  return 0;
}*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, std::vector<int>, long long int)':
ricehub.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for (int i = 0; i < x.size(); i++)
      |                   ~~^~~~~~~~~~
/tmp/cc8wjuyV.o: In function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status