PivotOJ

Akcija

시간 제한: 5000ms메모리 제한: 512MB출처: COCI 2021-2022BOJ 23851

문제

Christmas, a time for giving. Mr. Malnar is in need of gift ideas. Although deep in thought, the television program grabs his attention: “Special offer! This amazing product is on sale for just ww kunas. Call now because the offer is available only if you call within the next dd minutes. But that’s not all...”

There are nn different products on sale, where the ii-th product has a cost of wiw_i, and it’s available for order until the minute did_i (inclusive). Making a call to place an order requires one minute. A subset of products is called obtainable if it is possible to make a sequence of calls which order those products while meeting the mentioned deadlines. No product can be ordered more than once.

Mr. Malnar intends to buy as many products as possible, at the least possible price, but he’s not yet sure which products he should buy. He compares two obtainable subsets in the following way: the better obtainable subset is the one with more products, and if they have equal size, it’s the one that has a smaller total cost (sum of costs of chosen products).

Mr. Malnar will rank the obtainable subsets in the described manner and he will take into consideration kk of the best ones. Write a program which determines the size and the total cost for kk of the best obtainable subsets.

입력

The first line contains positive integers nn and kk - the number of different products and the number of obtainable subsets to be taken into consideration, respectively. kk will be less than or equal to the total number of obtainable subsets.

The following nn lines contain two positive integers wiw_i (1 ≤ w_i ≤ 10^9) and did_i (1 ≤ d_i ≤ n) - the cost of the ii-th product and the last minute for which the offers stands, respectively.

출력

In the i-th line print the size and the total cost of the i-th best obtainable subset.

힌트

Clarification of the second example: Products 1 and 2 can’t simultaneously be in an obtainable subset, so the three best obtainable subsets are {1, 3, 4}, {2, 3, 4} and {1, 3}.

예제

예제 1

입력
3 1
1 1
1 1
1 3
출력
2 2

예제 2

입력
4 3
1 1
10 1
2 3
10 3
출력
3 13
3 22
2 3

예제 3

입력
2 4
1 1
2 2
출력
2 3
1 1
1 2
0 0
코드를 제출하려면 로그인하세요.