leminhkt

78

Sep 14th, 2020 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. const short LOVE = 1411;
  6.  
  7.  
  8. int n, l, s;
  9. int cnt;
  10.  
  11.  
  12. int main(){
  13.     //freopen("Test.INP", "r", stdin);
  14.     //freopen("Test.OUT", "w", stdout);
  15.     cin.tie(NULL)->sync_with_stdio(false);
  16.  
  17.  
  18.     cin >> l >> n;
  19.     vector<pair<int, int>> a(n);
  20.     for (int i = 0; i < n; ++i)
  21.         cin >> a[i].second,
  22.         s += a[i].second,
  23.         a[i].first = i + 1;
  24.     while (s++ < l)
  25.         a.push_back({0, 1});
  26.     sort(a.begin(), a.end());
  27.     for (pair<int, int> &i : a)
  28.         if (i.first != 0) {
  29.             swap(i, a.front());
  30.             break;
  31.         }
  32.     do {
  33.         for (pair<int, int> i : a)
  34.             for (int j = 0; j < i.second; ++j)
  35.                 cout << i.first << ' ';
  36.         cout << '\n';
  37.     } while (++cnt < 1000 && next_permutation(a.begin(), a.end()));
  38.  
  39.  
  40.     return 0;
  41. }
Add Comment
Please, Sign In to add comment