#P8162. [JOI 2022 Final] 让我们赢得选举 / Let's Win the Election

    ID: 9237 远端评测题 1600ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP贪心2022Special JudgeO2优化JOI(日本)

[JOI 2022 Final] 让我们赢得选举 / Let's Win the Election

Problem Description

The JOI Republic has NN states, numbered 1N1 \sim N. In 2022, the JOI Republic will hold a presidential election. The election will be held separately in each state. The winner in each state will obtain one electoral vote from that state.

Rie will run for president, and she is planning to win the election. She decides to increase her credibility by giving speeches. After she gives speeches, the following events may occur.

  • If the total speech time in the ii-th state reaches AiA_i hours, she will win one electoral vote from that state.
  • If the total speech time in the ii-th state reaches BiB_i hours, she will gain one collaborator from that state.
  • It is possible that Rie cannot gain a collaborator in the ii-th state. In this case, Bi=1B_i = -1; otherwise, it is guaranteed that BiAiB_i \geq A_i.

A collaborator from the ii-th state can give speeches outside the ii-th state. Multiple people can give speeches in the same state at the same time. For example, if two people give speeches for xx hours at the same time in a state, the total speech time in that state will increase by 2x2 x hours. Speech time does not have to be an integer number of hours. We can ignore travel time between states.

Election day is approaching, and Rie wants to obtain KK electoral votes as quickly as possible.

Given the number of states and the information for each state, write a program to compute the minimum time required (in hours) to obtain KK electoral votes.

Input Format

The first line contains a positive integer NN.

The second line contains a positive integer KK.

The next NN lines describe the states. The ii-th of these lines contains two positive integers Ai,BiA_i, B_i.

Output Format

Print one line containing one number: the minimum time required (in hours) to obtain KK electoral votes.

If the absolute difference between your output and the correct answer is at most 0.010.01, then your submission will be judged correct. Your output must be in one of the following formats:

  • An integer (examples: 123, 0, -2022).
  • A sequence consisting of an integer, a dot, and a string of digits 090 \sim 9. It must not contain any separators. The number of digits after the decimal point is unlimited (examples: 123.4, -123.00, 0.00288).

Your output must not use exponential notation. For example, 1.23456e+05 and 1.23456e5 are not allowed.

3
3
1 5
2 3
4 5

5.500000000000000

7
4
4 -1
11 -1
6 -1
12 -1
36 -1
11 -1
20 -1

32.000000000000000

5
3
4 -1
5 -1
6 -1
7 7
8 8

11.500000000000000

7
5
28 36
11 57
20 35
19 27
31 33
25 56
38 51

62.166666666666664

20
14
106 277
175 217
170 227
164 245
118 254
139 261
142 270
185 200
162 241
153 239
128 264
103 299
147 248
158 236
160 232
183 205
194 197
135 260
153 234
128 260

644.203571428571422

Hint

[Sample Explanation #1]

By giving speeches according to the following plan, Rie will win the electoral vote in every state within 5.55.5 hours.

  • Give a speech in the 22-nd state for 22 hours and win one electoral vote.
  • Give another speech in the 22-nd state for 11 hour and gain one collaborator.
  • Give a speech in the 33-rd state together with the collaborator for 22 hours and win one electoral vote.
  • Give a speech in the 11-st state together with the collaborator for 0.50.5 hours and win one electoral vote.

This sample satisfies the properties of subtasks 3,4,5,6,73, 4, 5, 6, 7.

[Sample Explanation #2]

By giving speeches according to the following plan, Rie will obtain 44 electoral votes within 3232 hours.

  • Give a speech in the 11-st state for 44 hours and win one electoral vote.
  • Give a speech in the 22-nd state for 1111 hours and win one electoral vote.
  • Give a speech in the 33-rd state for 66 hours and win one electoral vote.
  • Give a speech in the 66-th state for 1111 hours and win one electoral vote.

This sample satisfies the constraints of subtasks 1,2,3,4,5,71, 2, 3, 4, 5, 7.

[Sample Explanation #3]

By giving speeches according to the following plan, Rie will obtain 33 electoral votes within 11.511.5 hours.

  • Give a speech in the 44-th state for 77 hours, win one electoral vote, and gain one collaborator.
  • Give a speech in the 11-st state for 44 hours and win one electoral vote. At the same time, the collaborator gives a speech in the 22-nd state for 44 hours.
  • Give a speech in the 22-nd state together with the collaborator for 0.50.5 hours and win one electoral vote.

This sample satisfies the constraints of subtasks 2,3,4,5,72, 3, 4, 5, 7.

[Sample Explanation #4]

This sample satisfies the constraints of subtasks 3,4,5,73, 4, 5, 7.

[Sample Explanation #5]

This sample satisfies the constraints of subtasks 4,5,74, 5, 7.


[Constraints]

This problem uses bundled testdata.

For 100%100\% of the testdata, 1KN5001 \le K \le N \le 500, 1Ai10001 \le A_i \le 1000, and AiBi1000A_i \le B_i \le 1000 or Bi=1B_i = -1.

  • Subtask 11 (55 points): Bi=1B_i = -1.
  • Subtask 22 (55 points): Bi=1B_i = -1 or Bi=AiB_i = A_i.
  • Subtask 33 (1111 points): N7N \le 7.
  • Subtask 44 (1212 points): N20N \le 20.
  • Subtask 55 (3333 points): N100N \le 100.
  • Subtask 66 (1111 points): K=NK = N.
  • Subtask 77 (2323 points): No additional constraints.

Translated from JOI 2022 Final T3 “選挙で勝とう / Let's Win the Election”.

Translated by ChatGPT 5