#P10229. [COCI 2023/2024 #4] Knjige
[COCI 2023/2024 #4] Knjige
Background
Translated from COCI 2023/2024 Contest #4 T2 “Knjige”.
Problem Description
Marko is at the Interliber book fair. He bought books in total, and the attractiveness of the -th book is . Marko placed all the books on a shelf in non-decreasing order of attractiveness from left to right.
Marko will spend minutes reading these books. For each book, he can either spend minutes to read it completely and gain inspiration, or spend minutes to only learn about it from the cover.
He will start reading from the leftmost book. After he finishes the current book (either completely or by looking at the cover), he starts reading the next book immediately to its right. The inspiration Marko gains is equal to the sum of the attractiveness values of the books he read completely. Determine the maximum inspiration Marko can have after minutes.
Note: If Marko starts reading a book but does not finish it before minute ends, then that book will not contribute to Marko’s inspiration.
Input Format
The first line contains four integers (, , ), representing the number of books, the time Marko spends reading, and the time required for complete reading and for reading the cover, respectively.
The second line contains integers (, ), representing the attractiveness values.
Output Format
Output one integer, the maximum inspiration value after minutes.
3 5 2 1
2 2 4
6
2 10 3 1
3 3
6
4 10 3 2
3 4 5 6
12
Hint
Sample Explanation 1
For example, Marko can achieve the maximum inspiration by reading books and completely, and reading only the cover of book .
Subtasks
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 7 | For , |
| 2 | 27 | |
| 3 | 36 | No additional constraints |
Translated by ChatGPT 5