include bits stdc using namespace std define int long long int class f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N, n, a, b, t;
class fastio {
public:
fastio() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
} __fastio;
//P is the number of problem solved
bool check(int p) {
//If score is >= t, then true else false
return ((p * a) - (n - p) * b >= t);
}
int binSearch(int lo, int hi) {
//Base Case
if(lo == hi) return lo;
if(lo + 1 == hi) {
if(check(lo)) return lo;
else return hi;
}
//Where stuff happens
int mid = lo + (hi - lo)/2;
if(check(mid)) binSearch(lo, mid);
else binSearch(mid+1, hi);
}
void solve() {
cin >> N;
while(N--) {
cin >> n >> a >> b >> t;
int ans = binSearch(1, 1e9);
if(ans > n) cout << "-1" << endl;
else cout << ans << endl;
}
}
signed main() {
__fastio;
solve();
return 0;
}