Holidays
Time limit2sMemory limit64 MB
Choose a weekly day off to maximize non-working days over a contract of E days, counting holidays across leap and normal years.
- Level
Medium7 of 10
- Topics
- Math, Prefix sum, Implementation, Number theory
- Solved
- No attempts yet
Problem
On a planet in the Alpha Centauri system, a week has days and a year has days. Years are numbered with consecutive positive integers: . Years numbered are leap years and have days. In a year, the days numbered are holidays. If a holiday falls on day of the year, it is observed only in leap years. The first day of the first year is the first day of the week.
A resident of the planet has decided to take a new job. Under the employment contract, he will hold this job for days, starting from the first day of year 1. By the contract, he may choose one day of the week (from 1 to ) as his day off. Holidays are also counted as non-working days. The resident wants to choose his day off so that during the contract period he has the maximum number of non-working days.
Write a program that finds this day of the week and computes the corresponding number of non-working days.
Input
The first line contains and , the number of days in a week and in a non-leap year, separated by a space (, ). The second line contains , the number of leap years, and the third line contains the numbers of the leap years in increasing order (, ). The next line contains , the number of holidays in a year, and the line after it contains in increasing order (). The last line contains (). The contract lasts no more than years.
Output
Output two numbers separated by a space: the number of the day of the week that is most advantageous to take as a day off, and the corresponding number of non-working days during the contract period. If there are several answers, output any of them.