Codeforces Round #469 (Div. 2) A. Left-handers, Right-handers and Ambidexters

时间:2022-06-25 09:25:51
A. Left-handers, Right-handers and Ambidexters

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

题意:给你l,r,a,代表只用左手玩球的,只用右手玩球的,两只手都会玩的人数,让你组合一个队伍,队伍中左手打球和右手打球的刚好对半均分。

思路:贪心,当l==r时,此时直接平均分配a即可。

当l不等于r时,先用a将少的那个补到l==r,如果有多的a,平均分配即可,当然如果a无法补到l==r,此时取小的那个就是答案。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
ll l,r,m;
int main()
{
    while(~scanf("%lld%lld%lld",&l,&r,&m))
    {
        if(l==r)   //l==r特判
        {
            if(m&1)printf("%lld\n",l+r+m-1);
            else printf("%lld\n",l+r+m);
        }
        else
        {
            if(l>r)swap(l,r);   //不等的情况,为了方便,直接保证l<r
            if(m<=r-l)printf("%lld\n",(m+l)*2);   //m不够让l==r
            else
            {
                m=m-(r-l);   //此时可以补到l==r
                l=r;
                if(m&1)printf("%lld\n",l+r+m-1);
                else printf("%lld\n",l+r+m);
            }
        }
    }
    return 0;
}