Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- #define int long long
- vector<vector<int>> gen_c5, gen_c3, gen_c2;
- void rec_c(vector<int>& x, int par, int len, int sz) {
- if (len == par) {
- if(par == 5) {
- gen_c5.push_back(x);
- }
- if (par == 3) {
- gen_c3.push_back(x);
- }
- if (par == 2) {
- gen_c2.push_back(x);
- }
- return;
- }
- int st = 0;
- if (len != 0) {
- st = x.back() + 1;
- }
- for (int j = st; j < sz; j++) {
- if (sz - j < par - len) {
- break;
- }
- x.push_back(j);
- rec_c(x, par, len + 1, sz);
- x.pop_back();
- }
- }
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- vector<int> sub;
- rec_c(sub, 2ll, 0ll, 10ll);
- sub.clear();
- rec_c(sub, 3ll, 0ll, 10ll);
- sub.clear();
- rec_c(sub, 5ll, 0ll, 10ll);
- vector<int> best[3];
- vector<int> best_w[3];
- set<pair<int, int>> win[3];
- int n; cin >> n;
- for (int i = 0; i < n; i++) {
- int d, m, a; cin >> d >> m >> a;
- win[0].insert({d, i});
- win[1].insert({m, i});
- win[2].insert({a, i});
- if ((int)win[0].size() > 10) {
- win[0].erase(win[0].begin());
- }
- if ((int)win[1].size() > 10) {
- win[1].erase(win[1].begin());
- }
- if ((int)win[2].size() > 10) {
- win[2].erase(win[2].begin());
- }
- }
- for(int j = 0; j < 3; j++) {
- for (auto& it : win[j]) {
- best_w[j].push_back(it.first);
- best[j].push_back(it.second);
- }
- }
- int ans = -1;
- struct Index {
- int fst = 0, sec = 0, th = 0;
- Index() {}
- Index(int _f, int _s, int _t) : fst(_f), sec(_s), th(_t) {}
- };
- Index res;
- for (int fst = 0; fst < (int)gen_c5.size(); fst++) {
- vector<int>& it_5 = gen_c5[fst];
- int now = 0;
- set<int> rs;
- for (int& i : it_5) {
- now += best_w[0][i];
- rs.insert(best[0][i]);
- }
- for (int sec = 0; sec < (int)gen_c3.size(); sec++) {
- vector<int>& it_3 = gen_c3[sec];
- bool ok = true;
- int sum2 = 0;
- set<int> del;
- for (int& i : it_3) {
- now += best_w[1][i];
- sum2 += best_w[1][i];
- if (rs.find(best[1][i]) != rs.end()) {
- ok = false;
- break;
- }
- del.insert(best[1][i]);
- rs.insert(best[1][i]);
- }
- if (!ok) {
- now -= sum2;
- for (auto& it : del) {
- rs.erase(it);
- }
- continue;
- }
- for (int th = 0; th < (int)gen_c2.size(); th++) {
- vector<int>& it_2 = gen_c2[th];
- bool ok = true;
- int sum = 0;
- for (int& i : it_2) {
- now += best_w[2][i];
- sum += best_w[2][i];
- if (rs.find(best[2][i]) != rs.end()) {
- ok = false;
- break;
- }
- }
- if (!ok) {
- now -= sum;
- continue;
- }
- if (ans < now) {
- ans = now;
- res = {fst, sec, th};
- }
- now -= sum;
- }
- now -= sum2;
- for (auto& it : del) {
- rs.erase(it);
- }
- }
- }
- for (int& i : gen_c5[res.fst]) {
- cout << best[0][i] + 1 << ' ';
- }
- cout << '\n';
- for (int& i : gen_c3[res.sec]) {
- cout << best[1][i] + 1 << ' ';
- }
- cout << '\n';
- for (int& i : gen_c2[res.th]) {
- cout << best[2][i] + 1 << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement