CatCoder Double Contest

AtCoder
IDarc201_a
Time2000ms
Memory256MB
Difficulty
> The problem setting of this problem is partially shared with Problem F. In the year $2222$, CatCoder will hold the CatCoder Double Contest (abbreviated as C2C). There are $N$ writers who have problem proposals. Each writer's problem proposals are classified into $3$ types by difficulty: Hard, Medium, Easy, and the $i$\-th writer has $A_i$, $B_i$, $C_i$ problem proposals of Hard, Medium, Easy, respectively. Each C2C simultaneously holds $2$ divisions, Div.1 and Div.2. The problem proposals required for each division are as follows: * Div.1: One Hard and one Medium problem proposal from the same writer * Div.2: One Medium and one Easy problem proposal from the same writer Note that **the writers for Div.1 and Div.2 do not necessarily have to be the same**. Also, each problem proposal can be used in at most one division of one C2C. Find the maximum number of times C2C can be held. $T$ test cases are given, so find the answer for each. ## Constraints * $1 \le T \le 10^5$ * $1 \le N \le 2 \times 10^5$ * $1 \le A_i,B_i,C_i \le 10^9$ * The sum of $N$ over all test cases is at most $2 \times 10^5$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $T$ $\text{case}_1$ $\text{case}_2$ $\vdots$ $\text{case}_T$ Each test case is given in the following format: $N$ $A_1$ $B_1$ $C_1$ $A_2$ $B_2$ $C_2$ $\vdots$ $A_N$ $B_N$ $C_N$ [samples]
Samples
Input #1
5
2
3 1 4
1 5 3
1
1 1 1
3
5 7 5
1 11 99
3 1 2
5
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
6
835549144 866512240 105679868
473233032 625162103 823002638
125467290 37501686 380787083
8043910 721085797 254272563
97327826 744196952 18713225
978152989 90127986 33086297
Output #1
2
0
7
2500000000
998830769

For the first test case, C2C can be held $2$ times by using problem proposals as follows:

Div.1

Div.2

$1$st time

Hard, Medium from the $1$st writer

Medium, Easy from the $2$nd writer

$2$nd time

Hard, Medium from the $2$nd writer

Medium, Easy from the $2$nd writer
API Response (JSON)
{
  "problem": {
    "name": "CatCoder Double Contest",
    "description": {
      "content": "> The problem setting of this problem is partially shared with Problem F. In the year $2222$, CatCoder will hold the CatCoder Double Contest (abbreviated as C2C). There are $N$ writers who have probl",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc201_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "> The problem setting of this problem is partially shared with Problem F.\n\nIn the year $2222$, CatCoder will hold the CatCoder Double Contest (abbreviated as C2C).\nThere are $N$ writers who have probl...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments