-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
65 lines (50 loc) · 1017 Bytes
/
Copy pathC.cpp
File metadata and controls
65 lines (50 loc) · 1017 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define cerr if(0) cerr
#endif
#define all(v) (v).begin(), (v).end()
#define X first
#define Y second
using ll = long long;
using ld = long double;
template<class T = int>
using V = vector<T>;
template<class T = int>
using VV = V<V<T>>;
template<class I, class J>
using P = pair<I, J>;
template<class T = int>
using PP = P<T, T>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto &&run_case = [&]() {
ll k, n, a, b;
cin >> k >> n >> a >> b;
if (n * b >= k) {
cout << -1 << '\n';
return;
}
auto &&solve = [&](ll m) {
return m * a + (n - m) * b < k;
};
ll h = n, l = 0;
for (int i = 0; i < 40; i++) {
ll m = (h + l) >> 1;
if (solve(m)) {
l = m;
} else {
h = m;
}
}
cout << (solve(h) ? h : l) << '\n';
};
int tc;
cin >> tc;
while (tc--) run_case();
return 0;
}