#P1376. [USACO05MAR] Yogurt factory 机器工厂

    ID: 371 远端评测题 1000ms 250MiB 尝试: 8 已通过: 3 难度: 3 上传者: 标签>贪心2005USACO福建省历届夏令营

[USACO05MAR] Yogurt factory 机器工厂

Description

Xiao T opened a machine factory. Over NN weeks, raw material costs and labor prices fluctuate; in week ii, producing one machine costs CiC_i yuan. If a machine is not sold, maintaining each machine costs SS yuan per week; this fee is constant.

The factory has received orders: in week ii, it must deliver YiY_i machines to the client. Machines produced in week ii, as well as inventory from previous weeks, can be used to fulfill the order.

Please compute the minimum total cost to complete all orders over these NN weeks.

Input Format

The first line contains two integers NN and SS. The next NN lines each contain two integers CiC_i and YiY_i.

Output Format

Output a single integer, the minimum cost.

4 5
88 200
89 400
97 300
91 500

126900

Hint

For 100%100\% of the testdata, 1N1041 \le N \le 10^4, 1Ci50001 \le C_i \le 5000, 1S1001 \le S \le 100, 0Yi1040 \le Y_i \le 10^4.

Translated by ChatGPT 5