Submission #551290

# Submission time Handle Problem Language Result Execution time Memory
551290 2022-04-20T08:25:40 Z AmShZ Rice Hub (IOI11_ricehub) C++11
Compilation error
0 ms 0 KB
//khodaya khodet komak kon
# include "ricehub.h"
# include <bits/stdc++.h>

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define fast_io                                         ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 1e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 1e9 + 7;//998244353;
const int base = 257;

int ptr, ans;
ll s, t;
set <pii> S, T;

ll calc(){
	while (SZ(S) < SZ(T)){
		pll x = *T.begin();
		T.erase(x);
		t -= x.A;
		S.insert(x);
		s += x.A;
	}
	while (SZ(T) + 1 < SZ(S)){
		pll x = *prev(S.end());
		S.erase(x);
		s -= x.A;
		T.insert(x);
		t += x.A;
	}
	if (!SZ(S))
		return 0;
	pll x = *prev(S.end());
	ll res = x.A * SZ(S) - s;
	res += t - x.A * SZ(T);
	return res;
}
int besthub(int R, int L, int X[], ll B){
	ptr = - 1;
	for (int i = 0; i < n; ++ i){
		if (i){
			s -= S.begin() -> A;
			S.erase(S.begin());
		}
		while (ptr < R && calc() <= B){
			++ ptr;
			if (ptr < R){
				T.insert({X[ptr], ptr});
				t += X[ptr];
			}
		}
		calc();
		ans = max(ans, ptr - i);
	}
	return ans;
}

/*
int main(){
	fast_io;

	count_routes();

	return 0;
}
*/
/*
5 5 2
1 0
1 2
3 2
1 3
4 2
2
3 1
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:65:22: error: 'n' was not declared in this scope
   65 |  for (int i = 0; i < n; ++ i){
      |                      ^