#P5911. [POI 2004] PRZ

    ID: 4880 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2004POI状态压缩,状压

[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: WW (the maximum weight the bridge can bear) and nn (the total number of team members).

The next nn lines each contain two integers: tt (the time needed for this member to cross) and ww (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 100%100\% of the testdata, 100W400100 \le W \le 400, 1n161 \le n \le 16, 1t501 \le t \le 50, 10w10010 \le w \le 100.

Translated by ChatGPT 5