CF1211C.Ice Cream
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Summer in Berland lasts n days, the price of one portion of ice cream on the i-th day is ci. Over the summer, Tanya wants to eat exactly k portions of ice cream. At the same time, on the i-th day, she decided that she would eat at least ai portions, but not more than bi (ai≤bi) portions. In other words, let di be equal to the number of portions that she eats on the i-th day. Then d1+d2+⋯+dn=k and ai≤di≤bi for each i.
Given that portions of ice cream can only be eaten on the day of purchase, find the minimum amount of money that Tanya can spend on ice cream in the summer.
伯兰的夏季持续 n 天,第 i 天一份冰淇淋的价格为 ci。在整个夏季,塔尼娅恰好想吃 k 份冰淇淋。同时,她在第 i 天决定至少吃 ai 份、至多吃 bi 份(其中 ai≤bi)。换言之,设 di 表示她在第 i 天吃的冰淇淋份数,则需满足 d1+d2+⋯+dn=k,且对每个 i 都有 ai≤di≤bi。
已知冰淇淋只能在购买当天食用,求塔尼娅在整个夏季购买冰淇淋所需的最少花费。
输入格式
The first line contains two integers n and k (1≤n≤2⋅105, 0≤k≤109) — the number of days and the total number of servings of ice cream that Tanya will eat in the summer.
The following n lines contain descriptions of the days, one description per line. Each description consists of three integers ai,bi,ci (0≤ai≤bi≤109, 1≤ci≤106).
第一行包含两个整数 n 和 k(1≤n≤2⋅105,0≤k≤109)—— 分别表示天数以及塔尼娅在整个暑假期间将吃的冰淇淋总份数。
接下来的 n 行描述了每一天的情况,每行描述一天。每行描述包含三个整数 ai,bi,ci(0≤ai≤bi≤109,1≤ci≤106)。
输出格式
Print the minimum amount of money that Tanya can spend on ice cream in the summer. If there is no way for Tanya to buy and satisfy all the requirements, then print -1.
输出塔尼娅在夏季购买冰淇淋所需的最少金额。如果塔尼娅无法购买并满足所有要求,则输出 −1。
输入输出样例
输入#1
3 7 3 5 6 0 3 4 3 3 3
输出#1
31
输入#2
1 45000 40000 50000 100000
输出#2
4500000000
输入#3
3 100 2 10 50 50 60 16 20 21 25
输出#3
-1
输入#4
4 12 2 5 1 1 2 2 2 3 7 3 10 4
输出#4
35
说明/提示
In the first example, Tanya needs to eat 3 portions of ice cream on the first day, 1 portions of ice cream on the second day and 3 portions of ice cream on the third day. In this case, the amount of money spent is 3⋅6+1⋅4+3⋅3=31. It can be shown that any other valid way to eat exactly 7 portions of ice cream costs more.
在第一个例子中,塔尼娅需要在第一天吃 3 份冰淇淋,第二天吃 1 份冰淇淋,第三天吃 3 份冰淇淋。此时花费的金额为 3⋅6+1⋅4+3⋅3=31。可以证明,任何其他恰好吃完 7 份冰淇淋的有效方案花费都更高。
输入解题思路,AI测评打分。不知道怎么写?