fork download
  1. #include<bits/stdc++.h>
  2. using namespace::std;
  3.  
  4. int main() {
  5. int n, k;
  6. scanf("%d %d", &n, &k);
  7. priority_queue<long long, vector<long long>, greater<long long>> Q;
  8. for(int i = 0; i < n; i++) {
  9. int x;
  10. scanf("%d", &x);
  11. Q.emplace(x);
  12. }
  13. int cnt = 0;
  14. while(Q.size() >= 2 and Q.top() < k) {
  15. long long x = Q.top(); Q.pop();
  16. long long y = Q.top(); Q.pop();
  17. Q.emplace(x + 2 * y);
  18. cnt += 1;
  19. }
  20. if(Q.top() < k) puts("-1");
  21. else printf("%d\n", cnt);
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
6 7
1 2 3 9 10 12
stdout
2