Advertisement
ivnikkk

Untitled

Dec 9th, 2022
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.11 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "bits/stdc++.h"
  3. using namespace std;
  4. #define all(a) a.begin(), a.end()
  5. #define int long long
  6. vector<vector<int>> gen_c5, gen_c3, gen_c2;
  7. void rec_c(vector<int>& x, int par, int len, int sz) {
  8.     if (len == par) {
  9.         if(par == 5) {
  10.             gen_c5.push_back(x);
  11.         }
  12.         if (par == 3) {
  13.             gen_c3.push_back(x);
  14.         }
  15.         if (par == 2) {
  16.             gen_c2.push_back(x);
  17.         }
  18.         return;
  19.     }
  20.     int st = 0;
  21.     if (len != 0) {
  22.         st = x.back() + 1;
  23.     }
  24.     for (int j = st; j < sz; j++) {
  25.         if (sz - j < par - len) {
  26.             break;
  27.         }
  28.         x.push_back(j);
  29.         rec_c(x, par, len + 1, sz);
  30.         x.pop_back();
  31.     }
  32. }
  33. signed main() {
  34. #ifdef _DEBUG
  35.     freopen("input.txt", "r", stdin);
  36.     freopen("output.txt", "w", stdout);
  37. #endif
  38.     ios_base::sync_with_stdio(false);
  39.     cin.tie(nullptr);
  40.     vector<int> sub;
  41.     rec_c(sub, 2ll, 0ll, 10ll);
  42.     sub.clear();
  43.     rec_c(sub, 3ll, 0ll, 10ll);
  44.     sub.clear();
  45.     rec_c(sub, 5ll, 0ll, 10ll);
  46.     vector<int> best[3];
  47.     vector<int> best_w[3];
  48.     set<pair<int, int>> win[3];
  49.     int n; cin >> n;
  50.     for (int i = 0; i < n; i++) {
  51.         int d, m, a; cin >> d >> m >> a;
  52.         win[0].insert({d, i});
  53.         win[1].insert({m, i});
  54.         win[2].insert({a, i});
  55.         if ((int)win[0].size() > 10) {
  56.             win[0].erase(win[0].begin());
  57.         }
  58.         if ((int)win[1].size() > 10) {
  59.             win[1].erase(win[1].begin());
  60.         }
  61.         if ((int)win[2].size() > 10) {
  62.             win[2].erase(win[2].begin());
  63.         }
  64.     }
  65.     for(int j = 0; j < 3; j++) {
  66.         for (auto& it : win[j]) {
  67.             best_w[j].push_back(it.first);
  68.             best[j].push_back(it.second);
  69.         }
  70.     }
  71.     int ans = -1;
  72.     struct Index {
  73.         int fst = 0, sec = 0, th = 0;
  74.         Index() {}
  75.         Index(int _f, int _s, int _t) : fst(_f), sec(_s), th(_t) {}
  76.     };
  77.     Index res;
  78.     for (int fst = 0; fst < (int)gen_c5.size(); fst++) {
  79.         vector<int>& it_5 = gen_c5[fst];
  80.         int now = 0;
  81.         set<int> rs;
  82.         for (int& i : it_5) {
  83.             now += best_w[0][i];
  84.             rs.insert(best[0][i]);
  85.         }
  86.         for (int sec = 0; sec < (int)gen_c3.size(); sec++) {
  87.             vector<int>& it_3 = gen_c3[sec];
  88.             bool ok = true;
  89.             int sum2 = 0;
  90.             set<int> del;
  91.            
  92.             for (int& i : it_3) {
  93.                 now += best_w[1][i];
  94.                 sum2 += best_w[1][i];
  95.                 if (rs.find(best[1][i]) != rs.end()) {
  96.                     ok = false;
  97.                     break;
  98.                 }
  99.                 del.insert(best[1][i]);
  100.                 rs.insert(best[1][i]);
  101.             }
  102.             if (!ok) {
  103.                 now -= sum2;
  104.                 for (auto& it : del) {
  105.                     rs.erase(it);
  106.                 }
  107.                 continue;
  108.             }
  109.             for (int th = 0; th < (int)gen_c2.size(); th++) {
  110.                 vector<int>& it_2 = gen_c2[th];
  111.                 bool ok = true;
  112.                 int sum = 0;
  113.                 for (int& i : it_2) {
  114.                     now += best_w[2][i];
  115.                     sum += best_w[2][i];
  116.                     if (rs.find(best[2][i]) != rs.end()) {
  117.                         ok = false;
  118.                         break;
  119.                     }
  120.                 }
  121.                 if (!ok) {
  122.                     now -= sum;
  123.                     continue;
  124.                 }
  125.                 if (ans < now) {
  126.                     ans = now;
  127.                     res = {fst, sec, th};
  128.                 }
  129.                 now -= sum;
  130.             }
  131.             now -= sum2;
  132.             for (auto& it : del) {
  133.                 rs.erase(it);
  134.             }
  135.         }
  136.     }
  137.     for (int& i : gen_c5[res.fst]) {
  138.         cout << best[0][i] + 1 << ' ';
  139.     }
  140.     cout << '\n';
  141.     for (int& i : gen_c3[res.sec]) {
  142.         cout << best[1][i] + 1 << ' ';
  143.     }
  144.     cout << '\n';
  145.     for (int& i : gen_c2[res.th]) {
  146.         cout << best[2][i] + 1 << ' ';
  147.     }
  148. }
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement