Logo
(追記) (追記ここまで)

32735번 - Card Pairs 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB43141134.375%

문제

You have a hand of cards, where each card has one of $n$ types. For each $i$ from 1ドル$ to $n,ドル you have $a_i$ cards with type $i,ドル and the bank has infinite cards with type $i$.

You can perform the following trade with the bank any number of times:

Choose any two cards with the same type from your hand, and exchange them for a single card from the bank with any type except the type of the cards you just exchanged. Note that the bank only has cards with types 1ドル$ through $n,ドル so you cannot trade for cards with any other types.

For example, here is a valid sequence of trades on the first sample case:

What is the maximum number of trades you can perform?

입력

The first line of the input contains a single integer $t$ (1ドル \le t \le 10^5$) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ (2ドル \le n \le 2\cdot 10^5$) --- the number of card types.

The second line of each test case contains $n$ integers $a_1, a_2 \cdots a_n$ (0ドル \le a_i \le 10^9$), where $a_i$ is the number of cards of type $i$ that you currently have.

It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル\cdot 10^5$.

출력

For each test case, print a single integer --- the maximum number of trades you can perform.

제한

예제 입력 1

9
4
2 0 0 1
2
5 2
6
1 5 0 6 7 1
4
1 1 0 1
2
4 2
7
1 2 4 8 4 2 1
2
1 1
4
0 0 0 0
3
1000000000 1000000000 1000000000

예제 출력 1

2
5
19
0
5
21
0
0
2999999999

힌트

The diagram above describes an optimal sequence of trades in the first test case.

In the fourth test case, it is impossible to perform any trades, since you don't start with any pair of cards with the same type, so the answer is 0ドル$.

출처

University > Rutgers University > Rutgers Programming Contest Fall 2024 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /