#GL0000312. Những ngày nghỉ lý tưởng (Ideal Holidays)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những ngày nghỉ lý tưởng (Ideal Holidays)
Ideal Holidays
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
In the Kingdom of AtCoder, a week consists of days. Days through are holidays, and days through are weekdays. The calendar repeats every week.
Takahashi has plans. The -th plan takes place days after today. The values are strictly increasing, but Takahashi has forgotten which day of the week today is.
Determine whether there exists a possible current day of the week such that every plan falls on a holiday.
Input
- The first line contains three integers .
- The second line contains strictly increasing integers .
Output
Print Yes if some choice of the current weekday makes all plans fall on holidays; otherwise print No.
Subtasks
- Subtask 0 (20 points): ; ; .
- Subtask 1 (30 points): ; ; .
- Subtask 2 (50 points): ; ; .
Examples
Example 1
Input
3 2 5
1 2 9
Output
Yes
Explanation
The week has days, with days and off. If today is day , the plans after days fall on days , all holidays.
Example 2
Input
2 5 10
10 15
Output
No
Explanation
The two plans are days apart in a -day cycle. No block of consecutive holidays can contain both days, even when the block crosses the end of a week.
Example 3
Input
4 347 347
347 700 705 710
Output
Yes
Explanation
The remainders modulo are , sorted as . The largest circular gap, from to in the next period, is days; the shortest arc containing all plans is days, so it fits in the holiday block.