#C9847. Maximum Words Typed
Maximum Words Typed
Maximum Words Typed
Alice wants to type as many words as she can within a given time limit. Each word requires a specified amount of time to type based on its complexity.
Given an integer \(N\) representing the number of words, a list \(T\) of \(N\) integers where the \(i\)-th element \(T_i\) indicates the time needed to type the \(i\)-th word, and an integer \(M\) representing the total available time, determine the maximum number of words that can be completely typed. In other words, find the largest integer \(k\) such that:
\(\sum_{i=1}^{k} T_i \le M\)
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains a single integer (N), the number of words.
- The second line contains (N) space-separated integers representing the time required to type each word (i.e., the list (T)).
- The third line contains a single integer (M), the total available time.
outputFormat
Output to standard output (stdout) a single integer representing the maximum number of words that can be fully typed within the given time limit.## sample
4
2 3 1 4
6
3