#P1977. 出租车拼车

    ID: 923 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>模拟动态规划,dp贪心洛谷原创

出租车拼车

Description

Suppose NN OIers plan to carpool. Time 00 is the current moment. The fare from the school gate to the destination is DD yuan, charged per taxi ride regardless of how many OIers are inside. Assume the contest starts exactly at SS minutes, so any taxi that passes the gate after SS minutes can be ignored. You are given the arrival times TiT_i and remaining seats ZiZ_i of all KK taxis that pass the gate within these SS minutes. For each taxi, the OIers may choose to let up to ZiZ_i people board (possibly 00), 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 2020 minutes, that means he spends an extra 2020 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 NN, KK, DD, SS, as described above.

Then follow KK lines. The ii-th line gives that the ii-th taxi arrives at minute TiT_i, and its number of remaining seats is ZiZ_i.

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 100%100\% of the testdata, N,K,D,S100N, K, D, S \le 100, 1Zi41 \le Z_i \le 4, 1TiTi+1S1 \le T_i \le T_{i+1} \le S.

Translated by ChatGPT 5