답안 #551291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551291 2022-04-20T08:26:02 Z AmShZ 쌀 창고 (IOI11_ricehub) C++11
100 / 100
72 ms 6604 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 < R; ++ 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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 3 ms 324 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 72 ms 6340 KB Output is correct
4 Correct 62 ms 6348 KB Output is correct
5 Correct 16 ms 852 KB Output is correct
6 Correct 16 ms 724 KB Output is correct
7 Correct 58 ms 6128 KB Output is correct
8 Correct 60 ms 6148 KB Output is correct
9 Correct 22 ms 980 KB Output is correct
10 Correct 22 ms 1008 KB Output is correct
11 Correct 64 ms 6604 KB Output is correct
12 Correct 58 ms 6436 KB Output is correct
13 Correct 18 ms 888 KB Output is correct
14 Correct 18 ms 832 KB Output is correct
15 Correct 48 ms 4816 KB Output is correct
16 Correct 44 ms 4772 KB Output is correct
17 Correct 53 ms 5660 KB Output is correct
18 Correct 53 ms 5668 KB Output is correct
19 Correct 56 ms 6072 KB Output is correct
20 Correct 53 ms 6012 KB Output is correct