#P8162. [JOI 2022 Final] 让我们赢得选举 / Let's Win the Election
[JOI 2022 Final] 让我们赢得选举 / Let's Win the Election
Problem Description
The JOI Republic has states, numbered . 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 -th state reaches hours, she will win one electoral vote from that state.
- If the total speech time in the -th state reaches hours, she will gain one collaborator from that state.
- It is possible that Rie cannot gain a collaborator in the -th state. In this case, ; otherwise, it is guaranteed that .
A collaborator from the -th state can give speeches outside the -th state. Multiple people can give speeches in the same state at the same time. For example, if two people give speeches for hours at the same time in a state, the total speech time in that state will increase by 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 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 electoral votes.
Input Format
The first line contains a positive integer .
The second line contains a positive integer .
The next lines describe the states. The -th of these lines contains two positive integers .
Output Format
Print one line containing one number: the minimum time required (in hours) to obtain electoral votes.
If the absolute difference between your output and the correct answer is at most , 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 . 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 hours.
- Give a speech in the -nd state for hours and win one electoral vote.
- Give another speech in the -nd state for hour and gain one collaborator.
- Give a speech in the -rd state together with the collaborator for hours and win one electoral vote.
- Give a speech in the -st state together with the collaborator for hours and win one electoral vote.
This sample satisfies the properties of subtasks .
[Sample Explanation #2]
By giving speeches according to the following plan, Rie will obtain electoral votes within hours.
- Give a speech in the -st state for hours and win one electoral vote.
- Give a speech in the -nd state for hours and win one electoral vote.
- Give a speech in the -rd state for hours and win one electoral vote.
- Give a speech in the -th state for hours and win one electoral vote.
This sample satisfies the constraints of subtasks .
[Sample Explanation #3]
By giving speeches according to the following plan, Rie will obtain electoral votes within hours.
- Give a speech in the -th state for hours, win one electoral vote, and gain one collaborator.
- Give a speech in the -st state for hours and win one electoral vote. At the same time, the collaborator gives a speech in the -nd state for hours.
- Give a speech in the -nd state together with the collaborator for hours and win one electoral vote.
This sample satisfies the constraints of subtasks .
[Sample Explanation #4]
This sample satisfies the constraints of subtasks .
[Sample Explanation #5]
This sample satisfies the constraints of subtasks .
[Constraints]
This problem uses bundled testdata.
For of the testdata, , , and or .
- Subtask ( points): .
- Subtask ( points): or .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): No additional constraints.
Translated from JOI 2022 Final T3 “選挙で勝とう / Let's Win the Election”.
Translated by ChatGPT 5