#K73552. Serving Guests
Serving Guests
Serving Guests
You are given D different dishes and G guests. Each dish i requires a preparation time represented by \(T_i\). Each guest has a favorite dish and a maximum waiting time \(w\). A guest can only be served if the preparation time of their favorite dish is at most their waiting time, i.e. \(T_f \leq w\) where \(f\) is the index of the dish. Note that each dish can be prepared only once. Your task is to determine the maximum number of guests that can be served their favorite dish in time.
Input Format:
The input is read from standard input (stdin
) and is formatted as follows:
- The first line contains two integers \(D\) and \(G\) separated by a space, representing the number of different dishes and the number of guests respectively.
- The second line contains \(D\) space-separated integers \(T_1, T_2, \dots, T_D\) denoting the preparation times for each dish.
- The following \(G\) lines each contain two space-separated integers. The first integer is the favorite dish index (1-indexed) and the second integer is the maximum waiting time for that guest.
Output Format:
Output a single integer representing the maximum number of guests that can be served their favorite dish within their waiting time.
inputFormat
The input is given through standard input (stdin
) with the following structure:
D G T1 T2 ... TD f1 w1 f2 w2 ... fG wG
Where:
- D and G are the number of dishes and guests.
- \(T_i\) is the preparation time for dish \(i\).
- Each guest provides their favorite dish index \(f\) and their maximum waiting time \(w\).
outputFormat
Output a single integer to standard output (stdout
) which is the maximum number of guests that can be served.
3 4
5 10 15
1 5
2 10
3 20
2 25
3