#P17199. [KOI 2026 #2] 工厂

    ID: 19515 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>Special Judge2026KOI(韩国)

[KOI 2026 #2] 工厂

Problem Description

A factory plans to operate from the night of day 00 to the night of day TT. Each day is divided into a daytime period and a nighttime period. In chronological order, the periods are: night of day 00, daytime of day 11, night of day 11, daytime of day 22, night of day 22, ⋯\cdots, daytime of day TT, night of day TT, for a total of 2T+12T+1 periods. During each daytime period, daytime production is performed, and during each nighttime period, nighttime security is performed.

To run the factory, it is necessary to choose and hire some employees from NN applicants. The ii-th applicant (1≤i≤N1 \le i \le N) has skill level AiA_i and contribution value BiB_i, and all applicants have distinct skill levels. If the ii-th applicant is hired, this employee will work in exactly three periods: the night of day Di−1D_i-1, the daytime of day DiD_i, and the night of day DiD_i, and will receive a base salary CiC_i. That is, each hired employee participates in two nighttime security shifts and one daytime production shift.

Work in each period is conducted as follows: all employees working in that period are sorted in increasing order of skill level to form a line, then starting from the front, they are paired up sequentially. That is, if there are 2k2k employees in total, then for each integer jj (1≤j≤k1 \le j \le k), the (2j−1)(2j-1)-th person and the (2j)(2j)-th person in the line form a pair.

All work must be done in pairs of two. Therefore, employees must be chosen so that the number of employees working in every period is even. It is allowed that no one works in some period; in that case, no work is performed in that period.

Each pair of employees produces the following results depending on the type of work:

  • Daytime production: During the day, each pair operates a production line to manufacture products, changing the factory’s total production profit. Specifically, if applicants xx and yy form a pair with skill levels satisfying Ax>AyA_x>A_y, then the total production profit increases by Bx−ByB_x-B_y. Note that this value may be negative.
  • Nighttime security: During the night, each pair patrols inside the factory and receives a night allowance. Specifically, if applicants xx and yy form a pair with skill levels satisfying Ax>AyA_x>A_y, then the two of them receive a total night allowance of Ax−AyA_x-A_y.

Before the factory starts operating (before the night of day 00), the total production profit is 00.

The factory’s total wage payment equals the sum of base salaries of all hired employees, plus the sum of all night allowances paid during all nights.

Given the information of the NN applicants, choose whom to hire to maximize “(total production profit) −- (total wages paid)”, and output the list of hired employees in this case.

Input Format

The first line contains two integers NN and TT separated by spaces.

The next NN lines give the information of the NN applicants. The ii-th line (1≤i≤N1 \le i \le N) contains four integers Ai,Bi,Ci,DiA_i,B_i,C_i,D_i separated by spaces, describing the ii-th applicant.

Output Format

The first line outputs the maximum value of “(total production profit) −- (total wages paid)”.

The second line outputs the number of employees to hire, KK.

The third line outputs, in any order, the indices of the KK employees to hire, separated by spaces. When K=0K=0, you may output an empty line, or you may omit this line.

If there are multiple feasible outputs, any one of them is considered correct.

6 2
21 0 1 1
13 25 0 2
22 20 3 2
20 5 2 2
4 23 0 2
25 16 8 1
7
4
1 3 4 6
5 2
40 23 10 1
59 22 2 2
32 7 10 2
52 30 0 1
38 10 3 1
0
0
12 3
6 19 4 2
32 0 1 3
12 0 4 3
25 7 0 2
35 15 5 1
28 25 5 2
19 27 3 3
30 13 3 2
1 24 5 3
20 11 0 2
2 1 5 2
24 28 3 2
20
8
1 3 4 6 7 10 11 12

Hint

Sample 1 Explanation

It is optimal to hire applicants 11 and 66 who work in the daytime of day 11, and applicants 33 and 44 who work in the daytime of day 22.

  • Daytime of day 11: employee 11 and employee 66 form a pair, so the total production profit increases by B6−B1=16B_6-B_1=16.
  • Daytime of day 22: employee 44 and employee 33 form a pair, so the total production profit increases by B3−B4=15B_3-B_4=15.

Thus, the total production profit is 16+15=3116+15=31.

  • Night of day 00: employee 11 and employee 66 form a pair, and a night allowance of A6−A1=4A_6-A_1=4 is paid.
  • Night of day 11: all four employees work. Sorted by skill level, the order is employee 44 (A4=20A_4=20), employee 11 (A1=21A_1=21), employee 33 (A3=22A_3=22), employee 66 (A6=25A_6=25). Employee 44 pairs with employee 11, and employee 33 pairs with employee 66. The night allowance paid that night is (A1−A4)+(A6−A3)=1+3=4(A_1-A_4)+(A_6-A_3)=1+3=4.
  • Night of day 22: employee 33 and employee 44 form a pair, and a night allowance of A3−A4=2A_3-A_4=2 is paid.

Thus, the total night allowance is 4+4+2=104+4+2=10.

The total wages paid are base salaries 1+3+2+8=141+3+2+8=14 plus night allowances 1010, totaling 2424. Therefore, the final value of “(total production profit) −- (total wages paid)” is 31−24=731-24=7.

Note that in this sample, the pairings in the daytime of day 11 and the night of day 11 are not the same.

Sample 2 Explanation

Hiring no one is optimal.

Constraints

  • All given numbers are integers.
  • 1≤T≤N≤5001 \le T \le N \le 500.
  • For each integer ii (1≤i≤N1 \le i \le N), 0≤Ai≤1 0000 \le A_i \le 1\,000.
  • For each integer ii (1≤i≤N1 \le i \le N), 0≤Bi≤1 0000 \le B_i \le 1\,000.
  • For each integer ii (1≤i≤N1 \le i \le N), 0≤Ci≤1 0000 \le C_i \le 1\,000.
  • For each integer ii (1≤i≤N1 \le i \le N), 1≤Di≤T1 \le D_i \le T.
  • A1,A2,⋯ ,ANA_1,A_2,\cdots,A_N are pairwise distinct.

Subtasks

  1. (1313 points) N≤20N \le 20.
  2. (1414 points) T=1T=1.
  3. (2020 points) T≤10T \le 10.
  4. (2222 points) For each integer dd (1≤d≤T1 \le d \le T), there are at most 88 applicants with Di=dD_i=d.
  5. (3131 points) No additional constraints.

Translated by ChatGPT 5