과정보단 결과에 집중해야 한다
Alice와 Bob의 사탕 개수를 똑같이 만들자
전체 합의 절반을 구할 때, 짝수와 홀수는 고려할 필요가 없다
- 제목
Three Piles of Candies
- 조건
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output
- 문제
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 Q 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.
- 입력
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≤10^16) — the number of candies in the first, second and third piles correspondingly.
- 출력
Print Q lines. The i-th line should contain the answer for the i-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).
예제 입력 1 | 4 1 3 4 1 10 100 10000000000000000 10000000000000000 10000000000000000 23 34 45 |
예제 출력 1 | 4 55 1500000000000 51 |
#include <iostream>
using namespace std;
int main() {
int test_case;
long long a, b, c, sum;
cin >> test_case;
for (int n = 0; n < test_case; n++) {
cin >> a >> b >> c;
sum = a + b + c;
cout << sum / 2 << endl;
}
return 0;
}