Problem Description
Problem Analysis
Similar to 【Codeforces】[670D2]Magic Powder - 2
It also works by checking whether mid burgers can be made
and then performing Binary Search
The only difference is the number of ingredients needed per burger
has to be counted from the string yourself
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
| #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[120];
__int64 cnt[3];
__int64 n[3];
__int64 p[3];
__int64 r;
bool judge(__int64 x) {
__int64 t=r;
for(int i=0; i<3; i++) {
if(t/p[i]+n[i]<x*cnt[i])
return false;
else
t-=max((__int64)0,(x*cnt[i]-n[i])*p[i]);
}
return true;
}
int main() {
while(scanf("%s",s)!=EOF) {
cnt[0]=cnt[1]=cnt[2]=0;
int ls=strlen(s);
for(int i=0; i<ls; i++) {
if(s[i]=='B')
cnt[0]++;
else if(s[i]=='S')
cnt[1]++;
else
cnt[2]++;
}
for(int i=0; i<3; i++)
scanf("%I64d",&n[i]);
for(int i=0; i<3; i++)
scanf("%I64d",&p[i]);
scanf("%I64d",&r);
__int64 l=0,r=1e13,res;
while(l<=r) {
__int64 mid=(l+r)/2;
if(judge(mid)) {
res=mid;
l=mid+1;
} else
r=mid-1;
}
printf("%I64d\n",res);
}
return 0;
}
|