C. Hamburgers
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

最大值最小,二分答案,判断可行
//
// main.cpp
// cf371c
//
// Created by Candy on 9/15/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
char s[];
ll n[],p[],c[],v,l,r,ans;
bool check(ll m){
ll tmp=v;
for(int i=;i<=;i++){
if(n[i]<m*c[i]){
tmp-=(m*c[i]-n[i])*p[i];
if(tmp<) return false;
}
}
return true;
}
int main(int argc, const char * argv[]) {
scanf("%s",s);
for(int i=;i<=;i++) cin>>n[i];
for(int i=;i<=;i++) cin>>p[i];
cin>>v; int len=strlen(s);
for(int i=;i<len;i++){
if(s[i]=='B') c[]++;
if(s[i]=='S') c[]++;
if(s[i]=='C') c[]++;
}
l=;r=v+n[]+n[]+n[];
while(l<r){//cout<<m<<"m \n";
ll m=(l+r+)/;
if(check(m)) l=m,ans=m;
else r=m-;
}
cout<<ans;
return ;
}
 

CF 371C-Hamburgers[二分答案]的更多相关文章

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

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

  2. [CF#592 E] [二分答案] Minimizing Difference

    链接:http://codeforces.com/contest/1244/problem/E 题意: 给定包含$n$个数的数组,你可以执行最多k次操作,使得数组的一个数加1或者减1. 问合理的操作, ...

  3. CF 1042A Benches——二分答案(水题)

    题目:http://codeforces.com/problemset/problem/1042/A #include<iostream> #include<cstdio> # ...

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

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

  5. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)

    The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...

  6. CF 1100E Andrew and Taxi(二分答案)

    E. Andrew and Taxi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 洛谷P2402 奶牛隐藏(网络流,二分答案,Floyd)

    洛谷题目传送门 了解网络流和dinic算法请点这里(感谢SYCstudio) 题目 题目背景 这本是一个非常简单的问题,然而奶牛们由于下雨已经非常混乱,无法完成这一计算,于是这个任务就交给了你.(奶牛 ...

  8. 洛谷CF1071E Rain Protection(计算几何,闵可夫斯基和,凸包,二分答案)

    洛谷题目传送门 CF题目传送门 对于这题,我无力吐槽. 虽然式子还是不难想,做法也随便口胡,但是一些鬼畜边界情况就是判不对. 首先显然二分答案. 对于每一个雨滴,它出现的时刻我们的绳子必须落在它上面. ...

  9. 【CF981F】Round Marriage(二分答案,二分图匹配,Hall定理)

    [CF981F]Round Marriage(二分答案,二分图匹配,Hall定理) 题面 CF 洛谷 题解 很明显需要二分. 二分之后考虑如果判定是否存在完备匹配,考虑\(Hall\)定理. 那么如果 ...

随机推荐

  1. [Dynamics CRM 2016]如何配置多语言显示

    1.安装相对应的语言包并安装 2015语言包下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=45014 2016语言包下载地 ...

  2. Source Insight基本使用和快捷键

    Source Insight基本使用和快捷键 为什么要用Source Insight呢?貌似是因为比完整的IDE要更快一些,比较利于查看大量的代码. 软件的安装很简单,设置好安装目录. 配置好文档路径 ...

  3. sqlite API模型

     每一个数据库连接可以包括多个数据库文件,一个主数据库文件和attached的几个数据库文件. 每一个数据库文件都有自己的B-tree和pager. 数据库连接(connection)和事务(tra ...

  4. js图形网站

    在做项目的时候难免会遇到要画各式各样的图形,这里推荐一个网站 http://echarts.baidu.com/doc/example.html 这个网站各种各样的图形都有,还有案例,相当不错

  5. IOS开发之多线程 -- GCD的方方面面

    前言:这篇GCD的博文是本人阅读了很多海内外大神的关于GCD的文章,以及结合之前自己对GCD的粗浅的认识,然后取其精华,去其槽粕,综合起来的笔记,而且是尽可能的以通熟易懂的并且是正确的理论论述方式呈现 ...

  6. 理解 Statement 和 PreparedStatement

    java,servlet中的PreparedStatement 接口继承了Statement,并与之在两方面有所不同:有人主张,在JDBC应用中,如果你已经是稍有水平开发者,你就应该始终以Prepar ...

  7. php页面静态化

    如何优化页面响应时间: 动态页面静态化 优化数据库 使用负载均衡 使用缓存 如果页面中的一些内容不经常改动,可以使用动态页面静态化.好处是:减少服务器脚本的计算时间:降低服务器的响应时间. 1.动态U ...

  8. Windows下好用到必须开机自启的小工具

    折腾过linux,黑苹果,最后还是回到了盖茨大叔的windows.得出的结论是,日常使用的话,折腾Linux还不如把精力去拿去折腾windows.分享下折腾的成果,介绍下一些很不错的小工具.     ...

  9. C# 重载运算符

    如果你想让自己定义的类型可以用运算符进行运算,那么可以通过重载运算符来实现: 示例: class Salary { public int RMB { get; set; } public static ...

  10. DROP_SNAPSHOT_RANGE过程不能清理表RM$_SNAPSHOT_DETAILS

    今天在测试.验证DROP_SNAPSHOT_RANGE不能彻底快照的过程中遇到了DROP_SNAPSHOT_RANGE无法清理WRM$_SNAPSHOT_DETAILS表中数据的情况,测试服务器版本为 ...