Asteroid Mining

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

요약
질량이 서로 나누어떨어지는 n개의 광물 조각 중에서 총 질량이 M 이하가 되도록 골라 가치 합의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
정렬, 동적 계획법, 그리디, 수학
정답자
아직 제출이 없습니다

문제

It is the year 2217 and Ryan is an asteroid miner. He makes a living by mining asteroids and selling them at the CCO (Celestial Cargo Outpost).

On his latest mining expedition, he has mined NN mineral chunks where the ii-th chunk has a value v_iv\_i and a mass m_im\_i. Ryan plans to transport a set of chunks to the CCO with his rocket, but he only has enough fuel to last one more trip. He calculated that the maximum total mass he can safely carry on his rocket is MM. Due to Ryan’s mining technique, the chunks exhibit a special property: for any two mineral chunks, one’s mass is divisible by the other chunk’s mass.

Help Ryan find the maximum total value he can ship to CCO while adhering to his rocket’s constraints.

입력

The first line will contain two space-separated integers NN (1≤N≤500,0001 ≤ N ≤ 500\\, 000) and MM (1≤M≤10121 ≤ M ≤ 10^{12}).

The next NN lines will each contain two space-separated integers v_iv\_i (1≤v_i≤10121 ≤ v\_i ≤ 10^{12}) and m_im\_i (1≤m_i≤10121 ≤ m\_i ≤ 10^{12}), representing the value and mass of the ii-th mineral chunk respectively. Additionally, for any two mineral chunks ii, jj (1≤i,j≤N1 ≤ i, j ≤ N), either m_i∣m_jm\_i | m\_j or m_j∣m_im\_j | m\_i, where a∣ba | b means that aa is a divisor of bb (i.e., b/ab/a is an integer).

출력

On one line, output one integer, the maximum total value Ryan can ship to CCO.

예제1

  1. 예제 1

    입력
    6 10
    1 1
    5 2
    200 6
    9 2
    6 2
    100 1
    
    예상 출력
    310