Crossing the Border

시간 제한15초메모리 제한2048 MB

요약
무게 제한이 있는 배낭들에 n개의 물건을 나누어 담아 각 배낭의 최대 세금의 합을 최소로 하고, 그 최소를 이루는 가짓수를 센다.
난이도

어려움10점 중 8점

유형
비트 연산, 동적 계획법, 백트래킹, 조합론
정답자
아직 제출이 없습니다

문제

Kostya F. is crossing the border of a certain country, carrying nn taxable items with him. Each item is characterized by two integers w_iw\_i and c_ic\_i: the weight of the item and the amount of tax that must be paid for transporting this item across the border.

Kostya needs to distribute all his items among several knapsacks. He can use any number of knapsacks. According to the airline's rules, the weight of each knapsack is limited, so the total weight of items inside each knapsack cannot exceed WW.

There are special rules for customs fees. When customs officers are checking the luggage, they open each knapsack, and set the tax for it equal to the maximum tax rate among the items inside this knapsack. The total tax is the sum of individual taxes for all knapsacks.

For purely practical reasons, Kostya wants to know what is the minimum total tax he can pay in order to cross the border with all his items. Also, out of pure curiosity, he wants to know in how many different ways this minimum can be achieved. Help him. Since the number of ways can be very large, you should find it modulo 998,244,353998\\,244\\,353.

Two ways to put items into knapsacks are considered the same if there is a bijection between knapsacks such that the corresponding knapsacks have exactly the same sets of items.

입력

The first line contains two integers: the number of items nn and the maximum weight of one knapsack WW (1≤n≤221 \le n \le 22; 1≤W≤5⋅1071 \le W \le 5 \cdot 10^7).

The next nn lines describe the items. The ii-th of them contains two integers: the weight w_iw\_i and tax c_ic\_i for item ii (1≤w_i≤W1 \le w\_i \le W; 1≤c_i≤5⋅1071 \le c\_i \le 5 \cdot 10^7).

출력

Print a line with two integers. The first must be the minimum total tax Kostya can pay. The second must be the number of ways to achieve that minimum, taken modulo 998,244,353998\\,244\\,353.

힌트

In the example, there are 44 different ways to distribute items among knapsacks with total tax equal to 99 (items are numbered from 11 to 55):

  • \[1,3],\[2,4,5]\[1, 3], \[2, 4, 5]: tax 5+4=95 + 4 = 9
  • \[1,4],\[2,3,5]\[1, 4], \[2, 3, 5]: tax 5+4=95 + 4 = 9
  • \[1,5],\[2,3,4]\[1, 5], \[2, 3, 4]: tax 5+4=95 + 4 = 9
  • \[1,2],\[3,4],\[5]\[1, 2], \[3, 4], \[5]: tax 5+3+1=95 + 3 + 1 = 9

예제1

  1. 예제 1

    입력
    5 5
    3 5
    1 4
    2 3
    2 2
    2 1
    
    예상 출력
    9 4