-
Notifications
You must be signed in to change notification settings - Fork 0
/
F - Tom & Jerry Space Adventure.cpp
107 lines (94 loc) · 1.96 KB
/
F - Tom & Jerry Space Adventure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Language: C++
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#ifdef LOCAL
#define dmp(x) cerr << _LINE_ << " " << #x << " " << x << endl
#else
#define dmp(x) void(0)
#endif
template <class t, class u>
void chmax(t &a, u b)
{
if (a < b)
a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
if (b < a)
a = b;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p)
{
return os << "{" << p.a << "," << p.b << "}";
}
template <class t>
ostream &operator<<(ostream &os, const vc<t> &v)
{
os << "{";
for (auto e : v)
os << e << ",";
return os << "}";
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main()
{
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
int n;
cin >> n;
int as = 0;
vc<pi> ab;
rep(_, n)
{
int a, b;
cin >> a >> b;
ab.eb(max(a, b), b);
as += a;
}
sort(all(ab), greater<pi>());
int s = 0, k = 0;
while (1)
{
s += ab[k++].a;
if (s >= as)
break;
}
int num = 1, den = 1;
auto upd = [&](int x, int y)
{
if (num * y > x * den)
tie(num, den) = tie(x, y);
};
rep(i, n)
{
int w = as - (s - ab[min(i, k - 1)].a);
if (w <= ab[i].b)
upd(w, ab[i].b);
}
num = den - num + den * (n - k);
den *= n;
int g = gcd(num, den);
cout << num / g << " " << den / g << endl;
}