#C10596. Max Delivered Messages
Max Delivered Messages
Max Delivered Messages
You are given n messages and a system schedule of length m. Each message i requires a certain number of online time slots (given by an integer in the array delivery_times
) to be delivered. The system schedule is represented by an array schedule
of length m where a value of 1 indicates that the system is online at that time slot and 0 indicates offline.
Your task is to determine the maximum number of messages that can be delivered, assuming that you may deliver the messages in increasing order of their required delivery time. Formally, let \(d_1, d_2, \dots, d_n\) be the sorted delivery times (in ascending order). Let \(A\) be the total number of online slots (i.e. the sum of the elements of schedule
). A message with delivery requirement \(d\) can be delivered if the sum of the delivery requirements of all messages delivered before plus \(d\) does not exceed \(A\).
Note: All formulas are written in \(\LaTeX\) format. For example, the condition for delivering \(k\) messages is:
\[ \sum_{i=1}^{k} d_i \leq A \]
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers
n
andm
separated by a space, wheren
is the number of messages andm
is the length of the schedule. - The second line contains
n
space-separated integers representing thedelivery_times
of the messages. - The third line contains
m
space-separated integers (each either 0 or 1) representing theschedule
.
outputFormat
Output a single integer representing the maximum number of messages that can be delivered.
The output should be printed to standard output (stdout).
## sample3 10
4 2 5
1 1 0 0 1 1 1 0 0 1
2