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

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
Copy
6
input
Copy
5 5 5
output
Copy
14
input
Copy
0 2 0
output
Copy
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.

先找到用左手和用右手的运动员中的最小值,加上最小值,再把剩下的左手或者右手运动员和全能选手配对,最后把剩下的全能的选手除二再加上去。最后cnt乘二就是答案。

#include <iostream>
#include <cstdio>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<cctype>
#include<list>
#include<stack>
#include<windows.h>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
    int l,r,a,i,j;
    while(scanf("%d%d%d",&l,&r,&a)!=EOF)
    {
    int cnt=0;
    if(l<=r)
    {
        cnt+=l;
        r-=l;
        if(r<=a)
        {
            cnt+=r;
            a-=r;
            cnt+=a/2;
        }
        else
        {
            cnt+=a;
        }
    }
    else if(l>r)
    {
        cnt+=r;
        l-=r;
        if(l<=a)
        {
            cnt+=l;
            a-=l;
            cnt+=a/2;
        }
        else
        {
            cnt+=a;
        }

    }
    printf("%d\n",cnt*2);
}
    return 0;
}
学会总结才能有收获!

猜你喜欢

转载自blog.csdn.net/qq_41629316/article/details/79975213