Advertisement
OIQ

vp2

OIQ
Nov 16th, 2019
242
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.  
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(0);
  11.     cout.tie(0);
  12.  
  13.     int n;
  14.     cin >> n;
  15.     vector <vector <int>> data(n, vector<int>(2));
  16.     vector <bool> ans(n);
  17.     int min = 100009, count = 0;
  18.  
  19.     for (int i = 0; i < n; ++i) {
  20.         int s1, s2;
  21.         cin >> s1 >> s2;
  22.  
  23.         data[i][0] = s1;
  24.         data[i][1] = s2;
  25.     }
  26.  
  27.     for (int i = 0; i < (1 << n); ++i) {
  28.         vector <bool> spec(n);
  29.         int count1 = 0, count2 = 0;
  30.         for (int j = 0; j < n; ++j) {
  31.             bool curr = (i & (1 << j)) != 0;
  32.             spec[j] = curr;
  33.             if (curr == 0)
  34.                 count1 += data[j][curr];
  35.             else
  36.                 count2 += data[j][curr];
  37.         }
  38.         count = max(count1, count2);
  39.  
  40.         if (count < min) {
  41.             min = count;
  42.             for (int k = 0; k < n; ++k)
  43.                 ans[k] = spec[k];
  44.         }
  45.     }
  46.     for (int i = 0; i < n; ++i)
  47.         cout << (int)ans[i] + 1 << " ";
  48.  
  49.     return 0;
  50. }
Advertisement
RAW Paste Data Copied
Advertisement