time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note

In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

题意就是n个人用2的倍数,m个人用3的倍数,然后所有人要求数不一样,要使得最大的数最小,输出结果。

二分讨论2的倍数,3的倍数,6的倍数,然后注意一下边界,wa在边界上了。。。

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,l,r,mid,ans;
int a,b,c;
while(~scanf("%d%d",&n,&m)){
int l=1,r=1e8;
while(l<=r){
mid=(l+r)/2;
a=mid/2;
b=mid/3;
c=mid/6;
if(a>=n&&b>=m&&a+b-c>=n+m){
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
printf("%d\n",ans);
}
return 0;
}

智障萌新,加油(ง •_•)ง

Codeforces 626 C. Block Towers-二分 (8VC Venture Cup 2016-Elimination Round)的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

  2. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  3. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  4. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  5. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  6. Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****

    F. Group Projects   There are n students in a class working on group projects. The students will div ...

  7. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  8. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  9. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

随机推荐

  1. React & shit Antd

    React & shit Antd https://ant.design/components/tooltip-cn/ https://ant.design/components/tag-cn ...

  2. MySQL密码忘了怎么办

    之前在ubuntu 12.04里安装了xampp,设置了mysql数据库root密码,今天需要增加个数据库,发现忘记之前设置的密码是什么了.经过一番摸爬滚打,终于搞明白了,注意以下的操作都是以linu ...

  3. 周记【距gdoi:91天】

    这星期挺没状态的.听蔡大神讲组合游戏,然后欢乐得以为自己懂了,然后看到题目就懵了,然后就各种乱各种走神……但是某大神们(kpm和child)疯狂地切题.然后又颓废了两个晚上后决定滚回去文化课(oi没状 ...

  4. 洛谷P1273 有线电视网 (树上分组背包)

    洛谷P1273 有线电视网 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节 ...

  5. HDU3829:Cat VS Dog(最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  6. Every Programmer Should Know These Latency Numbers

    Every Programmer Should Know These Latency Numbers 1秒=1000毫秒(ms) 1秒=1,000,000 微秒(μs) 1秒=1,000,000,00 ...

  7. Windows Time Client

    Timezone: UTC Coordinated Universal Time ====Perform by Local / administrator must,configure Time se ...

  8. ByteUtil 工具类

    ByteUtil 工具类 import java.io.FileOutputStream; import java.io.OutputStream; import java.nio.charset.C ...

  9. hihoCoder 1527 快速乘法

    #include<bits/stdc++.h> using namespace std; ; char a[N]; int main() { scanf(); ); ,r = n; ') ...

  10. 汕头市队赛 SRM 06 C 秀恩爱

    C 秀恩爱 SRM 06 背景&&描述         KPM坐在直升机上俯瞰小渔村景象.         渔村可看作二维平面,密密麻麻地到处都是单身狗,KPM当前所在坐标为(sx,s ...