Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. int n;
  5. int C[7];
  6. vector<int> I[7];
  7.  
  8. int main()
  9. {
  10.   cin >> n;
  11.   int tot = 0;
  12.   for (int i = 0; i < n; ++i)
  13.   {
  14.     int x;
  15.     cin >> x;
  16.     C[x] ++;
  17.     I[x].push_back(i);
  18.     tot += x;
  19.   }
  20.  
  21.   for (int c1 = 0; c1 <= C[1]; ++c1)
  22.   for (int c2 = 0; c2 <= C[2]; ++c2)
  23.   for (int c3 = 0; c3 <= C[3]; ++c3)
  24.   for (int c4 = 0; c4 <= C[4]; ++c4)
  25.   {
  26.     int sum = c1*1 + c2*2 + c3*3 + c4*4;
  27.     if (sum*2 == tot)
  28.     {
  29.       vector<int> R;
  30.       for (int i = 0; i < c1; ++i) R.push_back(I[1][i]);
  31.       for (int i = 0; i < c2; ++i) R.push_back(I[2][i]);
  32.       for (int i = 0; i < c3; ++i) R.push_back(I[3][i]);
  33.       for (int i = 0; i < c4; ++i) R.push_back(I[4][i]);
  34.  
  35.       cout << R.size() << endl;
  36.       sort(R.begin(), R.end());
  37.       for (int i = 0; i < R.size(); ++i)
  38.       {
  39.         if (i) cout << ' ';
  40.         cout << R[i]+1;
  41.       }
  42.       exit(0);
  43.     }
  44.   }
  45.  
  46.   cout << -1 << endl;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement