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

#GD0000071. Hàng đợi ngân hàng (Bank Queue)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hàng đợi ngân hàng (Bank Queue)

Bank Queue

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

The bank remains open for TT minutes, with service slots numbered 00 through T−1T-1. Customer ii wants to deposit cic_i units and must start service by minute tit_i or leave. Serving a customer takes exactly one minute, and each slot serves at most one customer. Maximize the total deposited money.

Input

The first line contains N,TN,T. Each of the next NN lines contains ci,tic_i,t_i.

Output

Print the maximum total cash.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤T≤471\le T\le47; 1≤ci≤1051\le c_i\le10^5, 0≤ti<T0\le t_i<T for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤T≤471\le T\le47; 1≤ci≤1051\le c_i\le10^5, 0≤ti<T0\le t_i<T for every ii.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; 1≤T≤471\le T\le47; 1≤ci≤1051\le c_i\le10^5, 0≤ti<T0\le t_i<T for every ii.

Examples

Input

5 3
100 0
50 1
120 0
100 2
35 2

Output

270

Explanation

Serve the 120120 customer at minute 00, the 5050 customer at minute 11, and the 100100 customer with deadline 22 at minute 22. The total is 270270. Only one of the two customers whose deadline is 00 can be served.