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. 如何查找SAP的事务代码清单

    SAP系统中,为了省去输入程序名称等繁琐步骤,SAP提供一种命令,称作‘事务代码’,通过执行事务代码达到快速进入相应程序的目的.那么在系统中如何去查找事务代码,事务代码和程序的对应关系如何呢?我们可以 ...

  2. SAP打印机配置

    SAP打印机配置 一.SAP打印原理 SAP的打印过程分两个步骤: 1.创建假脱机请求: 2.创建输出请求: 在点击打印按钮后,系统会提示创建假脱机请求后,你可以选择直接生成输出请求,或者手动生成输出 ...

  3. C C++ TDD单元测试非常好的书

    http://product.china-pub.com/199003 测试驱动的嵌入式C语言开发 Test Driven Development for Embedded C <测试驱动的嵌入 ...

  4. elipse + maven + tomcat + springMVC环境搭建

    1. java JDK安装 http://jingyan.baidu.com/article/b24f6c82c989da86bfe5dab2.html 2.eclipse安装 http://jing ...

  5. 查看Android系统是User模式还是Eng模式

    root@itek82_wet_kk:/ # cat default.prop # # ADDITIONAL_DEFAULT_PROPERTIES # ro.secure= ro.allow.mock ...

  6. 高仿精仿手机版QQ空间应用源码

    说明:本次QQ空间更新了以前非常基础的代码 更新内容一 更新了登陆界面二  增加了输入时密码时和登陆成功后播放音频的效果三 增加了导航条渐隐的效果(和真实QQ空间的导航条一样,首先透明,当tablev ...

  7. NSURLConnection获取一个MP3文件

    NSURLConnection网络请求 直接上代码-这个没什么说的,你们自己有兴趣可以自己试试 代码 #import "ViewController.h" @interface V ...

  8. Markdown语法手册

    Markdown 语法手册 Markdown 是一种轻量级标记语言,能将文本换成有效的XHTML(或者HTML)文档,它的目标是实现易读易写,成为一种适用于网络的书写语言. Markdown 语法简洁 ...

  9. c中的函数

    一. 什么是函数 l 任何一个C语言程序都是由一个或者多个程序段(小程序)构成的,每个程序段都有自己的功能,我们一般称这些程序段为“函数”.所以,你可以说C语言程序是由函数构成的. l 比如你用C语言 ...

  10. CSS 行内样式 页内样式 外部样式

    行内标签: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...