시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 16 | 13 | 6 | 75.000% |
You are a French chef and need to plan a very prestigious meal. As a French chef, you know all these weird politeness rules the French have on meals: which items must be served simultaneously, which need to be served first, how long you must wait between courses, etc.
For instance, the red wine accompanying the cheese must be served at least five minutes before the cheese plate arrives, otherwise people cannot choose what they consider the most adequate cheese to go with the wine. In addition, this wine needs to arrive at least twenty minutes after the main course, so people have time to finish the wine that has been served with the main course. And the cheese needs to be served around the same time as bread, otherwise people will eat bread and cheese separately. . . and so many other rules that you are not even sure you can satisfy all of them.
Fortunately, you have written all those rules down and you are now trying to organize the perfect meal. There are two kinds of rules:
You also know that a meal should always take at most K minutes in total (there must be at most K minutes between the first and last items served) and no dishes should ever be skipped.
Note that the constraints given are always inclusive of the bounds. For example, when A is served at t = 0 and B is served at t = 1, then both SIM A B 1 and BEF A B 1 are satified, and the meal composed of A and B takes 1 minute.
Your job is to help the chef determine whether it is possible to plan a meal that satisfies all rules.
The input is formed of N + 1 lines:
Limits
All given integers (N, K, the T’s) are between 0 and 1 000 inclusive.
The output should consist of a single line, whose content is either “YES” (if it is possible to organize a meal following all given constraints) or “NO” (otherwise).
7 150 BEF Hors_d_oeuvre Appetizer 30 BEF Appetizer Main_course 30 SIM Main_course Bread_1 5 BEF Main_course Cheese 30 SIM Cheese Bread_2 5 BEF Cheese Dessert 30 BEF Bread_1 Bread_2 45
YES
7 120 BEF Hors_d_oeuvre Appetizer 30 BEF Appetizer Main_course 30 SIM Main_course Bread_1 5 BEF Main_course Cheese 30 SIM Cheese Bread_2 5 BEF Cheese Dessert 30 BEF Bread_1 Bread_2 45
NO
ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2017 PD번