SHARE
TWEET

Untitled

a guest Jul 24th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.  
  11.     vector<int> v = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  12.     int n;
  13.     cin >> n;
  14.  
  15.     vector<long long> ans;
  16.     for (int i = 1; i < (1 << 10); i++) {
  17.         long long sum = 0;
  18.         for (int j = 0; j < 10; j++) {
  19.             if (i & (1 << j)) {
  20.                 sum = sum * 10 + v[j];
  21.             }
  22.         }
  23.         ans.push_back(sum);
  24.     }
  25.    
  26.     sort(ans.begin(), ans.end());
  27.     if (n > ans.size()) {
  28.         cout << -1 << '\n';
  29.     }
  30.     else {
  31.         cout << ans[n - 1] << '\n';
  32.     }
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top