Under construction

Still being built. Things may change

Lem0nad3's Bar

Time limit4sMemory limit512 MB

Summary
Choose at most K lemonades and the times to drink them so that the total of each fizz level times a drink-order weight is maximized.
Level

Medium7 of 10

Topics
Dynamic programming, Sorting, Greedy
Solved
No attempts yet

Problem

Geunsu has solved countless problems and is exhausted, so he goes into a lemonade bar to rest.

The bar has NN lemonades. Lemonade ii comes out at time tit_i with a fizz level of xix_i. The carbonation fades as time passes, so the fizz level drops by 1 for every unit of time. At time TT (T≥tiT \ge t_i), the fizz level of lemonade ii is xi−(T−ti)x_i - (T - t_i).

Geunsu has a thirst level of KK, so he can drink at most KK lemonades. A lemonade drunk while thirsty gives more happiness. The first lemonade he drinks gives happiness equal to KK times its fizz level. The second gives K−1K-1 times its fizz level, and the ii-th lemonade he drinks gives K+1−iK+1-i times its fizz level. In other words, if lemonade ii is the jj-th one he drinks, and he drinks it at time TT (T≥tiT \ge t_i), his happiness increases by (xi−(T−ti))×(K+1−j)(x_i - (T - t_i)) \times (K+1-j).

Drinking takes negligible time. Several lemonades can be drunk at the same time, in any order.

Geunsu starts with 0 happiness. Drink the lemonades in the best way to give Geunsu the maximum happiness.

Input

The first line contains NN and KK, separated by a space. (1≤N≤2 0001 \le N \le 2\,000; 1≤K≤121 \le K \le 12)

Each of the next NN lines contains tit_i and xix_i, separated by a space. (1≤ti,xi≤10121 \le t_i, x_i \le 10^{12})

Output

Print the maximum happiness Geunsu can obtain.

Examples3

  1. Example 1

    Input
    4 3
    2 7
    3 4
    7 1
    8 5
    
    Expected output
    34
    
  2. Example 2

    Input
    4 5
    1 100
    2 1
    10 10000
    100 1000
    
    Expected output
    54003
    
  3. Example 3

    Input
    5 4
    3 100
    1 20
    1 20
    1 20
    1 20
    
    Expected output
    508