|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|45 초 (추가 시간 없음)||1024 MB (추가 메모리 없음)||36||15||15||42.857%|
You are playing a new solitaire game called Prime Time. You are given a deck of cards, and each card has a prime number written on it. Multiple cards may have the same number.
Your goal is to divide the cards into two groups in such a way that the sum of the numbers in the first group is equal to the product of the numbers in the second group. Each card must belong to exactly one of the two groups, and each group must contain at least one card. The sum or product of a group that consists of a single card is simply the number on that card.
For example, in the image above, the left group has cards whose sum is 25 and the right group has cards whose product is 25. Therefore, this is a valid split into groups.
Your score is the sum of the numbers in the first group (which is equal to the product of the numbers in the second group), or 0 if you cannot split the cards this way at all. What is the maximum score you can achieve?
The first line of the input gives the number of test cases, T. T test cases follow. The first line of each test case contains a single integer M, representing the number of distinct prime numbers in your deck. Each of the next M lines contains two values: Pi and Ni, representing that you have exactly Ni cards with the prime Pi written on them.
Note that the total number of cards in your deck is the sum of all Nis.
For each test case, output one line containing
Case #x: y, where x is the test case number (starting from 1) and y is the maximum score you can achieve.
4 5 2 2 3 1 5 2 7 1 11 1 1 17 2 2 2 2 3 1 1 2 7
Case #1: 25 Case #2: 17 Case #3: 0 Case #4: 8
In Sample Case #1, the optimal split is: 11+2+7+3+2=5⋅5. Another split is also possible: 5+7+3+2+5=11⋅2, but it gives a lower score.
In Sample Case #2, note that cards with the same number can be placed in different groups.
Contest > Google > Code Jam > Google Code Jam 2021 > Round 1A B번