Dirichlet
시간 제한2.5초메모리 제한512 MB
최대 5종류 벽돌의 개수와 길이가 주어질 때, 모든 벽돌을 길이가 같은 N개 층으로 나눌 수 있는지 판정한다.
문제
Four friends Johann, Peter, Gustav and Lejeune are planning to build a brick wall. They already decided it should be a parallelepiped with one decimeter width and decimeters height, but they are still not sure about its length.
There were types of bricks available in the nearest store, and as they have no project of the wall, they simply bought bricks of type for each from to . A brick of type is a parallelepiped of size decimeters.
Due to the stability issues, all of the bricks should be put horizontally. That means each brick will be used in only one level of the wall. To build a wall of height , one needs to form sets of bricks. Every set can contain arbitrary number of bricks of any type, but the total length of all bricks in any set should be equal among all the sets.
Now friends wonder, whether it is possible to build a wall using all bricks they bought in the store.
입력
The first line of the input contains two integers and --- the number of brick types and the desired height of the wall respectively (, ).
Then follow lines describing the types. The -th of these lines contains two integers and --- the number of bricks of type bought by the friends and the length of a single brick of this type (, ).
출력
If it is possible to build a wall without breaking any requirements, print "Yes" on a single line of the output. Otherwise, print "No".
힌트
In the first example, the only possible way to construct the wall is to make one level from the only brick of the first type and four bricks of the third type, and another level from all bricks of the second type and one brick of the third type.
Please note that the time limit is harsh. Some extra optimizations may be required to get the problem accepted.