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. thrift的lua

    thrift的lua实现 最近要进行系统升级,后台的数据是根据城市区分的.担心新系统的稳定性及新数据的准确性,计划部分城市采用新接口.接口的入参里没有城市信息,只有经纬度坐标,需要调用一个thrift ...

  2. 【题解】SDOI2010地精部落

    强!强!强!强!劲啊劲啊劲啊!!!洛谷P2467 非常重要的,就在于发现以下的两条性质: 1.当i与i+1不相邻时,方案数是一样的:交换这两个数,<i+1的必然<i,>i+1的必然& ...

  3. 【题解】HNOI2008GT考试

    这题好难啊……完全不懂矩阵加速递推的我TAT 这道题目要求我们求出不含不吉利数字的字符串总数,那么我们有dp方程 : dp[i][j](长度为 i 的字符串,最长与不吉利数字前缀相同的后缀长度为 j ...

  4. [Leetcode] Same tree判断是否为相同树

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  5. Acunetix Web Vulnarability Scanner V10.5 详细中文手册

    目录: 0×00.什么是Acunetix Web Vulnarability Scanner ( What is AWVS?) 0×01.AWVS安装过程.主要文件介绍.界面简介.主要操作区域简介(I ...

  6. Ubuntu使用vim编辑器时出现上下左右键变成ABCD

    今天在配置安装php时,要打开配置文件做些修改,肯定是要使用到vim编辑器的,我按照之前的使用命令之类的,在用到上下左右键时居然出现了ABCD,这我就纳闷了,难道Ubuntu的vim编辑器和别的不一样 ...

  7. 关于border边框重叠颜色设置问题

    盒子模型包括:margin border padding content 在标准盒子模型中 conten不包括border和padding  就是他自身内容所包含的区域. 在IE盒子模型中    co ...

  8. Python学习笔记 - day5 - 文件操作

    Python文件操作 读写文件是最常见的IO操作,在磁盘上读写文件的功能都是由操作系统提供的,操作系统不允许普通的程序直接操作磁盘(大部分程序都需要间接的通过操作系统来完成对硬件的操作),所以,读写文 ...

  9. SUSE LINUX 11忘记密码的解决方法

    忘记ROOT的密码 1.重新启动机器,在出现grub引导界面后,在启动linux的选项里加上init=/bin/bash,通过给内核传递init=/bin/bash参数使得OS在运行login程序之前 ...

  10. Git-cheatsheet