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

原创 2018年04月17日 15:18:41
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;
}
学会总结才能有收获!
版权声明: https://blog.csdn.net/qq_41629316/article/details/79975213

任意位置显示html菜单

脚本说明:把如下代码加入区域中document.onclick = popUp   function popUp() {newX = window.event.x + document.body.sc...
  • denal
  • denal
  • 2003-03-10 10:21:00
  • 877

Codeforces Round #327 (div.2)(A B C D)

codeforces round #327 (div.2)
  • lincifer
  • lincifer
  • 2015-10-26 13:11:58
  • 1202

【解题报告】Codeforces Round #350 (Div. 2)

简略的解题报告。
  • TRiddle
  • TRiddle
  • 2016-05-09 00:24:12
  • 2514

[CF] 950A Left-handers, Right-handers and Ambidexters

A. Left-handers, Right-handers and Ambidexters time limit per test1 second memory limit per test256 ...
  • Gh0stCai
  • Gh0stCai
  • 2018-03-14 23:14:53
  • 17

Codeforces Round #464 (Div. 2) B. Hamster Farm

B. Hamster FarmDima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them ...
  • s540239976
  • s540239976
  • 2018-02-18 12:28:34
  • 224

A. Left-handers, Right-handers and Ambidexters

time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outpu...
  • jj12345jj198999
  • jj12345jj198999
  • 2018-03-30 17:56:41
  • 14

Codeforces Round #471 div.2 ABC题解

其实我是震惊的 A B C 其实我是震惊的 我被A题卡住了,21分钟才过.B题倒是挺快,29分钟.然后我一直想C和D. C是个数论题我觉得还能做,D我不会. 但是我发现1个...
  • qq_31908675
  • qq_31908675
  • 2018-03-24 14:16:58
  • 78

Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize

B. Run For Your PrizeYou and your friend are participating in a TV show &quot;Run For Your Prize&quo...
  • s540239976
  • s540239976
  • 2018-02-17 13:35:37
  • 214

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

#include&amp;lt;bits/stdc++.h&amp;gt; using namespace std; int main() { int a, b, c, ans = 0; ...
  • xiang_6
  • xiang_6
  • 2018-03-19 16:43:40
  • 23
收藏助手
不良信息举报
您举报文章:Codeforces Round #469 (Div. 2) A. Left-handers, Right-handers and Ambidexters
举报原因:
原因补充:

(最多只允许输入30个字)