Problem Description
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer qq independent queries.
Let's see the following example: [1,3,4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1,10,100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1≤q≤1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a,b and c (1≤a,b,c≤1016) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the ii-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Examples
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45Output
4
55
15000000000000000
51
题意:q 组询问,每组给出 a、b、c 三堆糖果,现在两个人要对这三堆糖果进行分配,第一个人能选择任意一堆,第二个人能在剩下的两堆中再选择任意一堆,然后对于剩下的最后一堆,两个人进行协商分配,使得两个人的糖果总数一样多,当分配完毕后,如果第一个人比第二个人糖多,会丢掉一些,使得两人糖果数相同,反之,第二个人也会进行丢弃,现在要使得分配后两个人的糖果数尽量多,问最后的糖果数
思路:无论怎么划分,最后本质上两个人的糖果数相同,因此只要求一下三堆糖果的和,再除以 2 即可,此外注意使用 long long
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int main(){
int q;
scanf("%d",&q);
while(q--){
LL a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
LL sum=a+b+c;
LL ava=sum/2;
printf("%lld\n",ava);
}
return 0;
}