제출 #938537

#제출 시각아이디문제언어결과실행 시간메모리
938537viwlesxqSure Bet (CEOI17_sure)C++17
100 / 100
60 ms3040 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
	return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
	return a < b ? (a = b) == b : false;
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n; cin >> n;
	vector<double> a(n), b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}
	sort(all(a)), sort(all(b));
	double res = 0;
	double A = a.back() - 2, B = b.back() - 2;
	a.pop_back(), b.pop_back();
	chmax(res, min(A, B));
	while (!a.empty() && !b.empty()) {
		if (A < B) {
			A += a.back() - 1;
			B += -1;
			a.pop_back();
		} else {
			B += b.back() - 1;
			A += -1;
			b.pop_back();
		}
		chmax(res, min(A, B));
	}
	while (!a.empty()) {
		A += a.back() - 1;
		B += -1;
		a.pop_back();
		chmax(res, min(A, B));
	}
	while (!b.empty()) {
		B += b.back() - 1;
		A += -1;
		b.pop_back();
		chmax(res, min(A, B));
	}
	cout << fixed << setprecision(4) << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...