Submission #806799

# Submission time Handle Problem Language Result Execution time Memory
806799 2023-08-04T10:00:28 Z Gangsta Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
// a >> b = a / pow(2,b)
// a << b = a * pow(2,b)
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define sz size()
#define ss second
#define ff first
#define N 200001
#define pll pair<ll,ll>

using namespace std;

bool check(int md, ll b, vector<int>arr){
	int n = arr.sz, p = (k-1) / 2;
	ll cost = 0;
	for(int i = 0; i < k; i++) cost += abs(arr[p] - arr[i]);
	if(cost <= b) return true;
	for(int i = k; i < n; i++){
		int x = arr[i - k], y = arr[i];
		int m = arr[p], mp = arr[p+1];
		p++;
		if(k&1){
			cost += x + y;
			cost -= m + mp;
		}
		else{
			cost += x + y;
			cost -= mp + mp;
		}
		if(cost <= B) return true;
	}
	return false;
}

int besthub(int r, int l, int x[N], ll b){
	vector <int> arr;
	for(int i = 0; i < r; i++) arr.pb(x[i]);
	int st = 1, en = r, md = 0, answer = -1;
	while(st <= en){
		md = (st + en) >> 1;
		if(check(md, b, arr)){
			answer = md;
			st = md + 1;
		}
		else en = md - 1;
	}
	return answer;
}

//int main(){
//	ll r, l, x[N], b;
//	cin >> r >> l;
//	for(int i = 0; i < r; i++) cin >> x[i];
//	cin >> b;
//	cout << besthub(r,l,x,b);
//}

Compilation message

ricehub.cpp: In function 'bool check(int, long long int, std::vector<int>)':
ricehub.cpp:15:23: error: 'k' was not declared in this scope
   15 |  int n = arr.sz, p = (k-1) / 2;
      |                       ^
ricehub.cpp:24:16: error: 'y' was not declared in this scope
   24 |    cost += x + y;
      |                ^
ricehub.cpp:28:16: error: 'y' was not declared in this scope
   28 |    cost += x + y;
      |                ^
ricehub.cpp:31:14: error: 'B' was not declared in this scope
   31 |   if(cost <= B) return true;
      |              ^