This page is still under construction.

Parts of this page are still being built. What you see may change.

Juice Blend

Time limit5sMemory limit512 MB

Summary
For each test case, choose integer shares of three juices summing to 10000 so that the most guests get at least their per-juice minimums.
Level

Medium7 of 10

Topics
Geometry, Implementation, Brute force, Greedy
Solved
No attempts yet

Problem

You are throwing a party, and you mix three juices into one drink: apple, banana and carrot. Call them juice A, juice B and juice C.

You decide what share of the drink each juice takes. A share is an integer in parts per ten thousand, and the three shares add up to exactly 1000010000.

Each guest has a minimum share for every juice. A guest likes the drink only if the share of each of the three juices is at least that guest's minimum for that juice.

Choose the shares so that as many guests as possible like the drink, and report that number.

Input

The first line contains an integer T, the number of test cases.

Each test case is given as follows.

  • One line with the integer N, the number of guests at the party.
  • N lines, one per guest, each with three space-separated integers "A B C", the minimum share that guest wants of each juice, in parts per ten thousand. They satisfy 0≤A,B,C≤100000 \le A, B, C \le 10000 and A+B+C≤10000A + B + C \le 10000.

Limits

  • 1≤T≤121 \le T \le 12
  • 1≤N≤50001 \le N \le 5000

Output

Print one line per test case, in the order the test cases appear in the input, containing "Case #X: Y". X is the test case number starting from 11, and Y is the largest number of guests who like the drink.

Hint

In the first test case of the first example, each of the three guests wants the drink made from a single juice, and the three juices differ, so only one guest can be satisfied.

In the second test case, any two of the three guests can be satisfied together.

In the third test case, shares of 33343334, 33333333 and 33333333 satisfy all five guests.

Examples3

  1. Example 1

    Input
    3
    3
    10000 0 0
    0 10000 0
    0 0 10000
    3
    5000 0 0
    0 2000 0
    0 0 4000
    5
    0 1250 0
    3000 0 3000
    1000 1000 1000
    2000 1000 2000
    1000 3000 2000
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 5
    
  2. Example 2

    Input
    3
    1
    0 0 0
    1
    10000 0 0
    1
    3333 3333 3334
    
    Expected output
    Case #1: 1
    Case #2: 1
    Case #3: 1
    
  3. Example 3

    Input
    2
    2
    5000 3000 2000
    4000 2000 3000
    2
    5000 3000 2000
    4000 2000 2000
    
    Expected output
    Case #1: 1
    Case #2: 2