G - Dream Team Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

NN 人の競技プログラマがいます。
ii 人目の競技プログラマは、所属大学が AiA_i、得意分野が BiB_i、強さが CiC_i です。

NN 人のうちの何人かによって構成されるチームであって、次の条件をともに満たすものをドリームチームと呼びます。

  • チームに属するどの 22 人の所属大学も異なる
  • チームに属するどの 22 人の得意分野も異なる

構成可能なドリームチームの人数の最大値を kk とします。各 i=1,2,,ki=1,2,\ldots,k について、次の問題を解いてください。

問題:ちょうど ii 人で構成されるドリームチームについて、チームに所属する人の強さの合計の最大値を求めてください。

制約

  • 1N3×1041 \leq N \leq 3\times 10^4
  • 1Ai,Bi1501 \leq A_i,B_i \leq 150
  • 1Ci1091 \leq C_i \leq 10^9
  • 入力に含まれる値は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 B1B_1 C1C_1
A2A_2 B2B_2 C2C_2
\vdots
ANA_N BNB_N CNC_N

出力

構成可能なドリームチームの人数の最大値を kk とする。
1行目には kk を出力し、その後、kk 行にわたって、i=1,2,,ki=1,2,\ldots,k のときの問題に対する答えを順に出力せよ。


入力例 1Copy

Copy
3
1 1 100
1 20 10
2 1 1

出力例 1Copy

Copy
2
100
11
  • ちょうど 11 人で構成されるドリームチームは、11 人目の競技プログラマからなるとき強さの合計が 100100 で最大になります。
  • ちょうど 22 人で構成されるドリームチームは、2,32,3 人目の競技プログラマからなるとき強さの合計が 1111 で最大になります。
  • ちょうど 33 人で構成されるドリームチームを作ることはできません。

入力例 2Copy

Copy
10
1 4 142135623
2 6 457513110
3 1 622776601
5 1 961524227
2 2 360679774
2 4 494897427
3 7 416573867
5 2 915026221
1 7 320508075
5 3 851648071

出力例 2Copy

Copy
4
961524227
1537802822
2032700249
2353208324

Score : 600600 points

Problem Statement

There are NN competitive programmers.
The ii-th competitive programmer belongs to University AiA_i, is good at Subject BiB_i, and has a power of CiC_i.

Consider a team consisting of some of the NN people. Let us call such a team a dream team if both of the following conditions are satisfied:

  • Any two people belonging to the team belong to different universities.
  • Any two people belonging to the team are good at different subjects.

Let kk be the maximum possible number of members of a dream team. For each i=1,2,,ki=1,2,\ldots,k, solve the following question.

Question: find the maximum sum of power of people belonging to a dream team consisting of ii people.

Constraints

  • 1N3×1041 \leq N \leq 3\times 10^4
  • 1Ai,Bi1501 \leq A_i,B_i \leq 150
  • 1Ci1091 \leq C_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN
A1A_1 B1B_1 C1C_1
A2A_2 B2B_2 C2C_2
\vdots
ANA_N BNB_N CNC_N

Output

Let kk be the maximum possible number of members of a dream team.
Print kk in the first line. Then, print kk more lines, each containing the answer to the question for i=1,2,,ki=1,2,\ldots,k, in this order.


Sample Input 1Copy

Copy
3
1 1 100
1 20 10
2 1 1

Sample Output 1Copy

Copy
2
100
11
  • The sum of power of members of a dream team consisting of exactly 11 person is 100100, when the team consists of the 11-st competitive programmer.
  • The sum of power of members of a dream team consisting of exactly 22 people is 1111, when the team consists of the 22-nd and the 33-rd competitive programmers.
  • It is impossible to form a dream team consisting of exactly 33 people.

Sample Input 2Copy

Copy
10
1 4 142135623
2 6 457513110
3 1 622776601
5 1 961524227
2 2 360679774
2 4 494897427
3 7 416573867
5 2 915026221
1 7 320508075
5 3 851648071

Sample Output 2Copy

Copy
4
961524227
1537802822
2032700249
2353208324


2025-04-28 (Mon)
06:32:49 +00:00