Problem descriptiondragon is watching competitions on TV. every competition is held between two competitors, and surely dragon's favorite. after each competition he will give a score of either 0 or 1 for each competitor and add it to the total score of that competitor. the total score begins with zero. here's an example: four competitors with name James, Victoria, Penghu, and digo. first goes a com Petition between Penghu and digo, and Dragon enjoys the competition and draw both 1 score for them. then there's a competition between James and Victoria, but this time dragon draw 1 for Victoria and 0 for James. lastly a competition between James and digo is held, but this time dragon really dislike the competition and give zeroes for each of them. finally we know the score for each one: James -- 0 , Victoria -- 1, Penghu -- 1, digo -- 1. All privileges t James are the winner!
However, Dragon's mom comes back home again and close the TV, driving dragon to his homework, and find out the paper with scores of all competitors. dragon's mom wants to know how many competition dragon watched, but it's hard through the paper. here comes the problem for you, given the scores of all competitors, at least how many competitions had dragon watched?
Inputthe first line of input contains only one integer T (<= 10), the number of test cases. Following t blocks, each block describe one test case.
For each test case, the first line contains only one integers n (<= 100000), which means the number of competitors. then a line contains N integers (A1, A2, A3 ,..., an ). AI (<= 1000000) means the score of I-th competitor.
Outputeach output shoshould occupy one line. each line shoshould start with "case # I:", with I implying the case number. then for each case just puts a line with one integer, implying the competition at least shoshould be watched by dragon.
Sample Input
132 3 4
Sample output
Case #1: 5 Question: give you n numbers whose initial values are 0. You can select either of them to perform the add operation, which can be 0 or 1, the minimum operation turns the N number into the N number given by the question. The idea is greedy. Obviously, we try to perform the plus 1 operation for both of them. Then we first find the largest, let him carry + 1, and then the sum of the first n-1 numbers. If it is smaller than the sum, the minimum operation is the maximum number. Otherwise, the operation is required.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef __int64 ll;using namespace std;int main() {int t, n, cas = 1;scanf("%d", &t);while (t--) {scanf("%d", &n);int Max = -1, a;ll sum = 0;for (int i = 0; i < n; i++) {scanf("%d", &a);sum += a;if (Max < a)Max = a;}sum -= Max;ll ans;if (Max >= sum)ans = Max;else ans = Max + (sum - Max + 1) / 2; printf("Case #%d: %I64d\n", cas++, ans);}return 0;}