bzoj#P2020. [USACO2010 Jan] Buying Feed, II

[USACO2010 Jan] Buying Feed, II

题目描述

Farmer John needs to travel to town to pick up kk pounds of feed. Driving DD miles with kk pounds of feed in his truck costs d×kd \times k cents. The county feed lot has nn stores (conveniently numbered 1n1\ldots n) that sell feed. Each store is located on a segment of the xx axis whose length is ee. Store ii is at location xix_i on the number line and can sell FJ as much as fif_i pounds of feed at a cost of cic_i cents per pound. Amazingly, a given point on the xx axis might have more than one store. FJ starts at location 00 on this number line and can drive only in the positive direction, ultimately arriving at location ee, with at least kk pounds of feed. He can stop at any of the feed stores along the way and buy any amount of feed up to the the store's limit. What is the minimum amount FJ has to pay to buy and transport the kk pounds of feed? FJ knows there is a solution. Consider a sample where FJ needs two pounds of feed from three stores (locations: 1,3,41,3,4) on a number line whose range is 050 \ldots 5:

0   1   2   3   4   5
+---|---+---|---|---+
    1       1   1      Available pounds of feed
    1       2   2      Cents per pound

It is best for FJ to buy one pound of feed from both the second and third stores. He must pay two cents to buy each pound of feed for a total cost of 44. When FJ travels from 33 to 44 he is moving 11 unit of length and he has 11 pound of feed so he must pay 1×1=11 \times 1 = 1 cents. When FJ travels from 44 to 55 he is moving one unit and he has 22 pounds of feed so he must pay 1×2=21 \times 2 = 2 cents. The total cost is 4+1+2=74+1+2 = 7 cents.

FJ 开车去买 kk 份食物,如果他的车上有 xx 份食物。每走一里就花费 xx 元。FJ 的城市是一条线,总共 ee 里路,有 e+1e+1 个地方,标号 050\sim 5。FJ 从 00 开始走,到 ee 结束(不能往回走),要买 kk 份食物。城里有 nn 个商店,每个商店的位置是 xix_i(一个点上可能有多个商店),有 fif_i 份食物,每份 cic_i 元。问到达 ee 并买 kk 份食物的最小花费。

输入格式

第一行:k,e,nk,e,n

第二行到第 n+1n+1 行:xi,fi,cix_i,f_i,c_i

输出格式

没有写明输出格式。

2 5 3
3 1 2
4 1 2
1 1 1
7

样例说明 1

在离家较近的两家商店里各购买一吨饲料,则花在路上的钱是 1+2=31+2=3,花在店里的钱是 2+2=42+2=4

数据规模与约定

对于 100%100\% 的数据,1k1001\leq k\leq 1001fi1001\leq f_i\leq 1001n1001\leq n\leq1001e3501\leq e\leq3500<xi<e0 < x_i < e1ci1061\leq c_i\leq 10^6

题目来源

Silver