SHARE
TWEET

Untitled

lalalalalalalaalalla Jun 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <math.h>
  14.  
  15. #define int long long
  16. #define ull unsigned long long
  17. #define all(a) a.begin(), a.end()
  18. #define pii pair<int, int>
  19. #define pb push_back
  20.  
  21. using namespace std;
  22.  
  23. void solve() {
  24.     int k, n, a, b;
  25.     cin >> k >> n >> a >> b;
  26.     int ans = 0;
  27.     if ((int)k / b <= n) {
  28.         cout << -1 << "\n";
  29.     } else {
  30. //        while ((int)k/a < n) {
  31. //            n--;
  32. //            k-=b;
  33. //        }
  34. //        ans = k/a;
  35. //        if (k % a == 0) {
  36. //            ans--;
  37. //        }
  38. //        cout << min(ans, n) << "\n";
  39.         int r = n, l = 0, mid;
  40.         while (r - l > 1) {
  41.             mid = (l + r) / 2;
  42. //            cout << mid * a + (n - mid) * b << "\n";
  43. //            cout << l << " " << r << "\n";
  44.             if (mid * a + (n - mid) * b >= k) {
  45.                 r = mid;
  46.             } else {
  47.                 l = mid;
  48.             }
  49.         }
  50. //        cout << l << " " << r << " " << mid << "\n";
  51.         if(r * a + (n - r) * b == k) cout << r - 1;
  52.         else if (r * a + (n - r) * b < k) cout << r;
  53.         else if (mid * a +(n - mid) * b == k) cout << mid - 1;
  54.         else if (mid * a +(n - mid) * b < k) cout << mid;
  55.         else if (l * a + (n - l) * b == k) cout << l - 1;
  56.         else if (l * a + (n - l) * b < k) cout << l;
  57.         cout << "\n";
  58.     }
  59. }
  60.  
  61. signed main()
  62. {
  63.     ios_base::sync_with_stdio(0);
  64.     cin.tie(0);
  65.     cout.tie(0);
  66. //    cout << fixed << setprecision(3);
  67.     int q;
  68.     cin >> q;
  69. //    vector<int> a(n);
  70. //    for (int i = 0; i < n; i++) cin >> a[i];
  71.     for (int w = 0; w < q; w++) solve();
  72. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top