제출 #563709

#제출 시각아이디문제언어결과실행 시간메모리
563709ngpin04Sure Bet (CEOI17_sure)C++14
100 / 100
592 ms3440 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) {
	return l + rd() % (r - l + 1);
}
const int N = 1e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
const int base = 1e4;

int need[2 * N];
int t[N];
int r[N];
int n;

int fix(string s) {
	int pos = 0;
	while (pos < (int) s.size() && s[pos] != '.')
		pos++;
	if (pos == (int) s.size())
		s += '.';
	int cnt = (int) s.size() - pos - 1;
	while (cnt < 4) {
		s += '0';
		cnt++;
	}
	
	// cerr << s << "\n";
	
	int res = 0;
	for (char c : s) 
		if (c != '.') 
			res = 10 * res + c - '0';
	return res;
}

bool solve(long long lim) {
	for (int i = 1; i <= 2 * n; i++)
		need[i] = 0;
			
	{
		long long tot = 0;
		for (int x = 1, i = 1; x <= 2 * n; x++) {
			while (i <= n && tot - x * base < lim) {
				tot += t[i];
				i++;
			}
			// cerr << tot << " " << x << " " << tot - x * base << " " << i << "\n";
			if (tot - x * base >= lim)
				need[x] += i - 1;
			else
				need[x] += oo;
		}
	}	
	
	{
		long long tot = 0;
		for (int x = 1, i = 1; x <= 2 * n; x++) {
			while (i <= n && tot - x * base < lim) {
				tot += r[i];
				i++;
			}
			if (tot - x * base >= lim)
				need[x] += i - 1;
			else
				need[x] += oo;
		}
	}
	
	for (int i = 1; i <= 2 * n; i++)
		if (need[i] <= i)
			return true;
	return false;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	freopen("sure.inp","r",stdin);
	freopen("sure.out","w",stdout);
	#endif
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string x,y;
		cin >> x >> y;
		t[i] = fix(x);
		r[i] = fix(y);
		cerr << t[i] << " " << r[i] << "\n";
	}
	sort(t + 1, t + n + 1, greater <int>());
	sort(r + 1, r + n + 1, greater <int>());

	long long lo = 0;
	long long hi = 1e18;
	while (hi - lo > 1) {
		long long mid = (lo + hi) >> 1;
		if (solve(mid))
			lo = mid;
		else
			hi = mid;
	}
	
	
	cout << lo / base << ".";
	{
		int cnt = to_string(lo % base).size();
		while (cnt < 4) {
			cout << 0;
			cnt++;
		}
		cout << lo % base;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...