fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. long long n, H;
  7. cin >> n >> H;
  8.  
  9. long long mx = 0, second = 0;
  10. int cnt = 0;
  11.  
  12. for (int i = 1; i <= n; i++)
  13. {
  14. long long x;
  15. cin >> x;
  16.  
  17. if (x > mx)
  18. {
  19. second = mx;
  20. mx = x;
  21. cnt = 1;
  22. }
  23. else if (x == mx)
  24. {
  25. cnt++;
  26. }
  27. else if (x > second)
  28. {
  29. second = x;
  30. }
  31. }
  32.  
  33. if (cnt >= 2)
  34. {
  35. cout << (H + mx - 1) / mx;
  36. return 0;
  37. }
  38.  
  39. long long l = 1;
  40. long long r = 2 * H / (mx + second) + 2;
  41.  
  42. while (l < r)
  43. {
  44. long long mid = (l + r) / 2;
  45.  
  46. long long damage =
  47. ((mid + 1) / 2) * mx
  48. + (mid / 2) * second;
  49.  
  50. if (damage >= H)
  51. {
  52. r = mid;
  53. }
  54. else
  55. {
  56. l = mid + 1;
  57. }
  58. }
  59.  
  60. cout << l;
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 5328KB
stdin
2 4
3 7
stdout
1