Hamburgers

http://codeforces.com/problemset/problem/371/C

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.

Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.

Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.

Input

The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).

The second line contains three integers nbnsnc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pbpspc (1 ≤ pb, ps, pc ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 1012) — the number of rubles Polycarpus has.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Output

Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.

Examples
input
BBBSSC
6 4 1
1 2 3
4
output
2
input
BBC
1 10 1
1 10 1
21
output
7
input
BSC
1 1 1
1 1 3
1000000000000
output
200000000001
 #include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#include<stack>
typedef long long ll;
using namespace std; ll a,b,c,d,e,f;
ll S,B,C;
ll num;
bool erfen(ll mid){
ll SS=mid*S-b;
if(SS<) SS=;
ll BB=mid*B-a;
if(BB<) BB=;
ll CC=mid*C-c;
if(CC<) CC=;
ll tmp=SS*e+BB*d+CC*f;
if(tmp>num) return false;
return true;
} int main(){ string str;
cin>>str; for(int i=;i<str.length();i++){
if(str[i]=='S') S++;
else if(str[i]=='B') B++;
else C++;
}
cin>>a>>b>>c>>d>>e>>f>>num;
ll L=,R=1e15,mid;
while(L<=R){
mid=L+R>>;
if(erfen(mid)){
L=mid+;
}
else{
R=mid-;
}
}
cout<<R<<endl; }

Hamburgers的更多相关文章

  1. Codeforces Round #218 (Div. 2) C. Hamburgers

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. CodeForces 371C Hamburgers

    B题又耽误时间了...人太挫了.... C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes i ...

  3. B - Hamburgers

    Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...

  4. Codeforces 371C Hamburgers (二分答案)

    题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...

  5. C. Hamburgers

    Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...

  6. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers

    题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...

  7. H Kuangyeye and hamburgers

    链接:https://ac.nowcoder.com/acm/contest/338/H来源:牛客网 题目描述 Kuangyeye is a dalao of the ACM school team ...

  8. cf C. Hamburgers

    http://codeforces.com/contest/371/problem/C 二分枚举最大汉堡包数量就可以. #include <cstdio> #include <cst ...

  9. CodeForces 371C Hamburgers(经典)【二分答案】

    <题目链接> 题目大意: 给以一段字符串,其中只包含"BSC"这三个字符,现在有一定量免费的'B','S','C‘,然后如果想再买这三个字符,就要付出相应的价格.现在总 ...

随机推荐

  1. ES之七:配置文件详解

    安装流程 http://www.elasticsearch.org/overview/elkdownloads/下载对应系统的安装包(我下载的是tar的),下载解压以后运行es根目录下bin目录的el ...

  2. Appium录制脚本520-2

    1.录制自动化脚本 场景:启动雪球,点击我的,登陆雪球,选择手机及其他登陆,输入手机号 2.使用Java进行测试Appium测试 2.1创建Java工程 file-创建maven工程-填写GroupI ...

  3. VM虚拟机占内存非常大

    我发现每次打开虚拟机占用内存非常大,经常会卡死,后来上网找原因,发现内存设置的问题,所以我就修改了虚拟机的内存,网上说如果是win7,内存设置需要1-2G,如果是xp,512M就够了. 经测试,内存还 ...

  4. python 网页抓取并保存图片

    #-*-coding:utf-8-*- import os import uuid import urllib2 import cookielib '''获取文件后缀名''' def get_file ...

  5. 什么是DSCP,如何使用DSCP标记搭配ROS策略

    一.什么是DSCP DSCP:差分服务代码点(Differentiated Services Code Point),IETF于1998年12月发布了Diff-Serv(Differentiated ...

  6. IP地址与子网掩码

    IP地址 众所周知,为了确保通信时能相互识别,在internet上的每台主机都必须有一个唯一的标识,即主机的IP地址.IP协议就是根据IP地址来实现信息传递的. IP地址由32位(4字节)二进制数组成 ...

  7. Unreal Engine 4 反射机制的实现

    转自:http://blog.csdn.net/noahzuo/article/details/51482255 反射机制 反射机制指的是程序可以在运行期间进行检测和修改自己状态的能力. UE4引擎使 ...

  8. 浅析PHP7新功能及语法变化总结

    标量类型声明 有两种模式: 强制 (默认) 和 严格模式. 现在可以使用下列类型参数(无论用强制模式还是严格模式): 字符串(string), 整数 (int), 浮点数 (float), 以及布尔值 ...

  9. ORM创建 脚本运行

  10. SignalR (一)

    关于SignalR 因近期要在项目中使用 SignalR 来开发实时web 程序,可在这之前,对SignalR 的了解并不是很多,甚至不知道 SignalR 到底是用来干什么的,可是在经过这段时间的学 ...