CF1211C.Ice Cream

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Summer in Berland lasts nn days, the price of one portion of ice cream on the ii -th day is cic_i . Over the summer, Tanya wants to eat exactly kk portions of ice cream. At the same time, on the ii -th day, she decided that she would eat at least aia_i portions, but not more than bib_i ( aibia_i \le b_i ) portions. In other words, let did_i be equal to the number of portions that she eats on the ii -th day. Then d1+d2++dn=kd_1+d_2+\dots+d_n=k and aidibia_i \le d_i \le b_i for each ii .

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.

输入格式

The first line contains two integers nn and kk ( 1n21051 \le n \le 2\cdot10^5 , 0k1090 \le k \le 10^9 ) — the number of days and the total number of servings of ice cream that Tanya will eat in the summer.

The following nn lines contain descriptions of the days, one description per line. Each description consists of three integers ai,bi,cia_i, b_i, c_i ( 0aibi1090 \le a_i \le b_i \le 10^9 , 1ci1061 \le c_i \le 10^6 ).

输出格式

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

    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 33 portions of ice cream on the first day, 11 portions of ice cream on the second day and 33 portions of ice cream on the third day. In this case, the amount of money spent is 36+14+33=313\cdot6+1\cdot4+3\cdot3=31 . It can be shown that any other valid way to eat exactly 77 portions of ice cream costs more.

首页