-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1400B.cpp
More file actions
50 lines (41 loc) · 935 Bytes
/
CF_1400B.cpp
File metadata and controls
50 lines (41 loc) · 935 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
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
using namespace std;
int follower_take_total(ll s, ll w, ll cnts, ll cntw, ll p) {
if (s > w)
return follower_take_total(w, s, cntw, cnts, p);
if (s * cnts >= p)
return p / s;
return cnts + min((p - s * cnts) / w, cntw);
}
int main() {
int T;
cin >> T;
for (int t = 0; t < T; t++) {
int p, f;
cin >> p >> f;
ll cnts, cntw;
cin >> cnts >> cntw;
ll s, w;
cin >> s >> w;
ll best = 0;
for (ll cs = 0; cs <= cnts; cs++)
if (cs * s <= p) {
ll cw = min((p - cs * s) / w, cntw);
best = max(best, cs + cw + follower_take_total(s, w, cnts - cs, cntw - cw, f));
}
cout << best << endl;
}
}