luogu#P1977. 出租车拼车
出租车拼车
Background
Once, little x went to a contest. Although the school was not far from the venue, little x still wanted to take a taxi. Taxis in the university town are a bit quirky: they do “carpooling.” That is, whether you ride alone or as a group, the total fare is the same per taxi ride (each taxi can seat at most passengers excluding the driver). Coincidentally, a group of OIers from the same school were gathered at the school gate that day, and everyone decisively decided to carpool to the venue.
Here comes the problem: taxis kept passing by, but they were either full or had only one or two seats left. The OIers felt that getting on those would be a bad deal, and little x thought so too.
Problem Description
Suppose OIers plan to carpool. Time is the current moment. The fare from the school gate to the destination is yuan, charged per taxi ride regardless of how many OIers are inside. Assume the contest starts exactly at minutes, so any taxi that passes the gate after minutes can be ignored. You are given the arrival times and remaining seats of all taxis that pass the gate within these minutes. For each taxi, the OIers may choose to let up to people board (possibly ), or skip this taxi entirely.
Time is money: each OIer’s waiting time in minutes at the gate is counted as spending the same amount of money. For example, if little x waits minutes, that means he spends an extra yuan.
Under the requirement that all OIers can reach the venue before the contest starts, compute the minimum total amount of money they need to spend.
Input Format
Each test case starts with four integers , , , , as described above.
Then follow lines. The -th line gives that the -th taxi arrives at minute , and its number of remaining seats is .
Times are given in chronological order.
Output Format
For each test case, output one line. If all of them can reach the venue before the contest starts, output a single integer representing the minimum amount of money (in yuan). Otherwise, output impossible.
2 2 10 5
1 1
2 2
14
Hint
Constraints: For of the testdata, , , .
Translated by ChatGPT 5