Codeforces Round #469 (Div. 2)

开学啦!

A. Left-handers, Right-handers and Ambidexters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and aambidexters, who can play with left or right hand.

The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.

Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.

Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

Input

The only line contains three integers lr and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

Output

Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.

Examples
input
Copy
1 4 2
output
6
input
Copy
5 5 5
output
14
input
Copy
0 2 0
output
0
Note

In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.

In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.


#include<iostream>
#include <stdio.h>  
#include <string.h>  
#include<algorithm>
using namespace std;

int main()
{
	int l, r, both;
	cin >> l >> r >> both;
	int ans = 0;
	if (l == 0 && r == 0)//ok
		ans = both % 2 ==0? both : both - 1;
	else if ((l == 0 && r != 0 )  || (r==0&&l!=0) ) {
		int tmp =max(r,l);
		int d = both - tmp;
		if (d ==0)ans =2* both;
		if (d > 0) {
			ans = tmp * 2;
			if (d % 2 == 0)ans += d;
			else  ans += max(d - 1,0);
		}
		if (d < 0) {
			ans = both * 2;

		}
	
	}
	
	else if (l != 0 && r != 0) {
		if (l == r) {
			ans = l * 2;
			if (both % 2 == 0)ans += both;
			else
				ans += max(0, both - 1);
		}
		if ((l > r )|| (r > l)) {
			int t1 = l, t2 = r;
			r = min(l, r);
			ans = r * 2;
			//cout << ans;
			int d = abs(t1-t2);
			if (both > d) {
				if (both % 2 == 0) {
					ans += (d * 2);
					int k = both - d;
					if (k % 2 == 0)ans += k;
					else ans += max(0, k - 1);
				}
				else if (both % 2 != 0) {
					int k = both - d;
					ans +=( d * 2);
					if (k % 2 == 0)ans += k;
					else {
						ans += max(k - 1, 0);
					}
				}
			}
			if (both == d) {
				ans += (both * 2);
			}
			if (both < d) {
				ans += (both * 2);
			}

		}
	}
	if (ans <= 0)cout << 0;
	else
		cout << ans;
	return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值