#P5911. [POI 2004] PRZ
[POI 2004] PRZ
Description
The bridge is very old, so it cannot hold things that are too heavy. At any moment, the total weight of the people on the bridge cannot exceed a fixed limit. Therefore, the team can only cross the bridge in several batches. Only after one batch has completely crossed can the next batch start crossing.
Each person needs a specific amount of time to cross the bridge. For one batch, the time taken should be counted as the slowest person's time in that batch. Each person also has a specific weight. You need to determine how to split the team into batches so that the total time is minimized.
Input Format
The first line contains two integers: (the maximum weight the bridge can bear) and (the total number of team members).
The next lines each contain two integers: (the time needed for this member to cross) and (this member's weight).
Output Format
Output one integer, the minimum total time needed to cross the bridge.
100 3
24 60
10 40
18 50
42
Hint
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号