#P1167. Maximum Problem Selection

    ID: 13759 Type: Default 1000ms 256MiB

Maximum Problem Selection

Maximum Problem Selection

With the contest approaching, Xiao A decided to practice problems non-stop, dedicating every minute before the exam to solve as many problems as possible. The current time is given in the format: yyyy mm dd hh MM, and the exam time is given in the format: yyyy2 mm2 dd2 hh2 MM2. All the time between these two moments is devoted to solving problems. Each problem has an associated time (in minutes) required to write it, and Xiao A cares only about the number of problems solved, not their quality.

You are given a list of problems from the online judge. Choose the maximum number of problems such that the total required time does not exceed the available time between the current moment and the exam. The greedy strategy works: select the easiest (least time consuming) problems first.

Note: Leap years must be considered. A year is a leap year if and only if $$year \% 400 == 0$$ or $$ (year \% 4 == 0 \text{ and } year \% 100 != 0) $$. Assume the current calendar system has been used since ancient times.

inputFormat

The input consists of the following lines:

  • The first line contains five integers: yyyy mm dd hh MM representing the current time.
  • The second line contains five integers: yyyy2 mm2 dd2 hh2 MM2 representing the exam time.
  • The third line contains an integer n denoting the number of problems.
  • The fourth line contains n integers, where each integer represents the required time (in minutes) needed to solve a problem.

outputFormat

Output a single integer: the maximum number of problems that Xiao A can solve before the exam.

sample

2023 10 15 12 0
2023 10 15 13 0
5
30 10 20 40 50
3