fork download
  1. /*
  2. Task: 1183C
  3. Date: Dec 25, 2020
  4. Author: aLittleLove (Minh Vu)
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. void Solve()
  12. {
  13. int64_t k, n, a, b; cin >> k >> n >> a >> b;
  14. int64_t l = 0, r = n, ans = -1;
  15. while (l<=r)
  16. {
  17. int64_t mid = (l + r) >> 1ll;
  18. if (k - mid * a - (n - mid) * b > 0)
  19. {
  20. ans = mid;
  21. l = mid + 1;
  22. }
  23. else r = mid - 1;
  24. }
  25. cout << ans << '\n';
  26. }
  27.  
  28. int main()
  29. {
  30. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  31. //freopen("input.txt","r",stdin);
  32. int nTest; cin >> nTest;
  33. while (nTest--) Solve();
  34. return 0;
  35. }
Success #stdin #stdout 0s 4776KB
stdin
6
15 5 3 2
15 5 4 3
15 5 2 1
15 5 5 1
16 7 5 2
20 5 7 3
stdout
4
-1
5
2
0
1