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

C. Block Towers
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 andm 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 height4, and the students using three-block pieces can make towers of height3, 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 heights3 and 6 with three-block pieces, for a maximum height of8 blocks.


题意:有n个人在用2的倍数,有m个人在用3的倍数,所有人的数都要求不一样,你要使得最大数最小,然后问你这个答案是多少


思路:二分讨论一下2的倍数,3的倍数,6的倍数就好了,注意边界


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#define MAXN 1010000
#define LL long long
#define ll __int64
#include<iostream>
#include<algorithm>
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
int n,m;
int check(int x)
{
	if(x/2<n||x/3<m||x/2+x/3-x/6<n+m)
	return 0;
	return 1;
}
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int l=0,r=10000000;
		while(r>l+1)
		{
			int mid=(l+r)/2;
			if(check(mid))
			r=mid;
			else
			l=mid;
		}
		printf("%d\n",r);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值