PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000127. Valera hái trái cây (Valera and Fruits)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Valera hái trái cây (Valera and Fruits)

Valera and Fruits

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Fruit tree ii produces bib_i fruits that ripen on day aia_i. These fruits may only be harvested on days aia_i and ai+1a_i+1. At most vv fruits can be harvested per day. Maximize the total collected.

Input

The first line contains n,vn,v. The next nn lines contain ai,bia_i,b_i.

Output

Print the maximum number of fruits harvested.

Subtasks

  • Subtask 1 (20 points): 1≤n,v≤201\le n,v\le 20; 1≤ai,bi≤30001\le a_i,b_i\le3000.
  • Subtask 2 (30 points): 1≤n,v≤5001\le n,v\le 500; 1≤ai,bi≤30001\le a_i,b_i\le3000.
  • Subtask 3 (50 points): 1≤n,v≤30001\le n,v\le 3000; 1≤ai,bi≤30001\le a_i,b_i\le3000.

Examples

Input

2 3
1 5
2 3

Output

8

Explanation

Harvest three fruits on day 11; two old fruits and one new fruit on day 22; then two remaining fruits on day 33. Total 88.