W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem [email protected].
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, zapraszamy na serwery Discord. Są one moderowane przez społeczność, ale członkowie zespołu technicznego też są tam aktywni.
Tug of war is a very popular sport in Byteland. The rules are easy: two teams pull a rope in opposite directions. The annual Byteland tug of war charity is taking place, and a lot of contestants have signed up. As the fair play commissioner, your job is to divide the contestants into two teams, such that the game can go on for a long time.
Since a total of contestants have signed up, each team will consist of contestants. The rope has spots on the left side and spots on the right side. The tug of war elite of Byteland are a picky bunch: each contestant has exactly one spot on the left side of the rope and one spot on the right side that he or she wants to use. Furthermore, you know the strength of each contestant.
The organizer has now asked you the following: Given an integer , is it possible to create two teams, such that each team has contestants, each contestant uses a spot that he or she wants to use (of course no two contestants share a spot), and the sums of strengths of the two teams differ by at most ?
The first line of input contains a positive integer , specifying the number of spots on each side of the rope, and an integer , specifying the maximum difference of teams' strengths. For simplicity, we number the contestants from 1 to .
Each of the following lines describes one contestant: the -th of these lines contains three positive integers , and (, ), which specify that contestant has strength and wants to use either spot on the left side of the rope or spot on the right side of the rope.
In the first and only line of output your program should write either YES or NO, depending on whether it is possible to create two teams satisfying the requirements stated above.
For the input data:
4 1 1 1 1 2 1 2 2 2 8 1 2 2 3 3 5 3 3 2 4 4 1 4 4 2
the correct result is:
YES
For the input data:
2 5 1 1 1 1 2 4 2 2 1 2 1 4
the correct result is:
NO
Explanation to the example: In the first example we can assign contestants 1, 3, 6 and 7 to the left side (which results in a team of strength ) and contestants 2, 4, 5 and 8 to the right side (which results in a team of strength ). The difference of strengths between teams is 1.
In the second example both players of strength 4 have to be in the same team, thus the minimal difference of strengths between teams is 6.
Subtask | Conditions | Points |
1 | 18 | |
2 | 30 | |
3 | , | 23 |
4 | 29 |