Submission #311351

# Submission time Handle Problem Language Result Execution time Memory
311351 2020-10-10T00:49:57 Z LucaDantas Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include "ricehub.h"
#include<algorithm>
#include<cstdio>

using ll = long long;

constexpr int maxn = 1e5+10;

ll pref[maxn];

inline ll itv(int l, int r) { return pref[r] - (l?pref[l-1]:0); }

ll cost(int l, int r, int a[]) {
	if(l == r) return 0;
	int m = (l+r) >> 1;
	int pos = a[m];
	ll cost = 1ll*pos*(m-l+1) - itv(l, m);
	cost += itv(m+1, r) - 1ll*pos*(r-m);
	return cost;
}

int besthub(int n, int l, int a[], ll b)
{
	int ans = 0;
	pref[0] = a[0];
	for(int i = 1; i < n; i++)
		pref[i] = pref[i-1]+a[i];
	for(int i = 0; i < n; i++) {
		int l = i, r = n-1, best = -1;
		while(l <= r) {
			int m = (l+r) >> 1;
			if(cost(i, m, a) <= b)
				best = m, l = m+1;
			else
				r = m-1;
		}
		assert(best != -1);
		ans = std::max(ans, best - i);
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:37:3: error: 'assert' was not declared in this scope
   37 |   assert(best != -1);
      |   ^~~~~~
ricehub.cpp:4:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    3 | #include<cstdio>
  +++ |+#include <cassert>
    4 |