-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathC.cpp
61 lines (47 loc) · 1.1 KB
/
C.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string s;
cin >> s;
ll len = s.length();
ll cntB = 0, cntC = 0, cntS = 0, B, C, S;
cin >> B >> S >> C;
ll costB, costC, costS;
cin >> costB >> costS >> costC;
ll total;
cin >> total;
for(int i = 0; i < len; i++) {
if(s[i] == 'B') cntB++;
else if(s[i] == 'C') cntC++;
else if(s[i] == 'S') cntS++;
}
ll lo = 0, hi = 10000000000000;
ll ans = 0;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
ll tmpB, tmpC, tmpS;
if(cntB * mid <= B)
tmpB = 0;
else
tmpB =costB * (cntB * mid - B);
if(cntS * mid <= S)
tmpS = 0;
else
tmpS = costS * (cntS * mid - S);
if(cntC * mid <= C)
tmpC = 0;
else
tmpC = costC * (cntC * mid - C);
ll sum = tmpB + tmpS + tmpC;
if(sum <= total) {
ans = mid;
lo = mid + 1;
}
else
hi = mid - 1;
}
cout << ans << endl;
return 0;
}