문제
Bessie is planning an infinite adventure in a land with
Bessie has
입력
The first line contains two space-separated integers:
The second line contains
For
For
출력
Print
부분문제
| 번호 | 점수 | 조건 |
|---|---|---|
| #1 | 25점 | |
| #2 | 25점 | |
| #3 | 25점 | |
| #4 | 25점 | 추가 제약 조건 없음 |
예제 #1
5 4
1 2 1 2 8
2
3 4
4
2 3
5 5 5 5 5 1 5 5
2 4 3
3 3 6
5 3 2
5 3 7
2
2
5
4
Bessie's first three adventures proceed as follows:
In the first adventure, she goes from city
2 at time4 to city3 at time5 , to city4 at time6 , to city2 at time7 .In the second adventure, she goes from city
3 at time3 to city4 at time4 , to city2 at time5 , to city4 at time6 , to city2 at time7 , to city4 at time8 , to city2 at time9 .In the third adventure, she goes from city
5 at time3 to city5 at time4 , to city5 at time5 .
예제 #2
5 5
1 2 1 2 8
2
3 4
4
2 3
5 5 5 5 5 1 5 5
2 4 3
3 2 6
5 3 2
5 3 7
5 3 1000000000000000000
2
3
5
4
2