-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.cpp
63 lines (49 loc) · 1.13 KB
/
messages.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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
const ll N = 2e5 + 8;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vi m(n);
vi k(n);
for (ll i = 0; i < n; i++) {
cin >> m[i] >> k[i];
}
ll bestt = 1;
ll bestans = 0;
vi bestpath;
for (ll t = 1; t <= 20; t++) {
vpi coeff(N);
for (ll i = 0; i < N; i++) {
coeff[i] = {0, i};
}
for (ll i = 0; i < n; i++) {
coeff[m[i]].first += min(t, k[i]);
}
sort(coeff.rbegin(), coeff.rend());
ll cans = 0;
vi path;
for (ll i = 0; i < t; i++) {
cans += coeff[i].first;
path.push_back(coeff[i].second);
}
if (cans * bestt > bestans * t) {
bestans = cans;
bestt = t;
bestpath = path;
}
}
cout << bestt << endl;
for (ll i = 0; i < bestt; i++) {
cout << bestpath[i] << " ";
}
cout << endl;
return 0;
}