eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Roller Coaster

Roller Coaster

Bessie has gone on a trip, and she's riding a roller coaster! Bessie really likes riding the roller coaster, but unfortunately she often gets dizzy. The roller coaster has a number of distinct sections that Bessie rides in order. At the beginning of the ride, Bessie's dizziness and fun levels are both at 0. For each section of the roller coaster, Bessie can either keep her eyes open or keep them closed (and must keep them that way for the whole section). If she keeps her eyes open for a section, her total fun increases by a Fun factor for that section, and her dizziness increases by a Dizziness factor for that section. However, if she keeps her eyes closed for the section, her total fun will not change, but her dizziness will decrease by a value that's constant for the entire roller coaster. (Note that her dizziness can never go below 0.) If, at any point, Bessie's dizziness is above a certain limit, Bessie will get sick. Write a program to find the maximum amount of fun Bessie can have without getting sick. \InputFile There will be several test cases in the input. Each test case will begin with a line with three integers: \textbf{N K L} Where \textbf{N} (\textbf{1} ≤ \textbf{N}\textit{ }≤ \textbf{1000}) is the number of sections in this particular roller coaster, \textbf{K} (\textbf{1} ≤ \textbf{K}\textit{ }≤ \textbf{500}) is the amount that Bessie's dizziness level will go down if she keeps her eyes closed on any section of the ride, and \textbf{L} (\textbf{1} ≤ \textbf{L}\textit{ }≤ \textbf{300000}) is the limit of dizziness that Bessie can tolerate - if her dizziness ever becomes larger than \textbf{L}, Bessie will get sick, and that's not fun! Each of the next \textbf{N} lines will describe a section of the roller coaster, and will have two integers: \textbf{F D} Where \textbf{F} (\textbf{1} ≤ \textbf{F}\textit{ }≤ \textbf{20}) is the increase to Bessie's total fun that she'll get if she keeps her eyes open on that section, and \textbf{D} (\textbf{1} ≤ \textbf{D}\textit{ }≤ \textbf{500}) is the increase to her dizziness level if she keeps her eyes open on that section. The sections will be listed in order. The input will end with a line with three \textbf{0}s. \OutputFile For each test case, output a single integer, representing the maximum amount of fun Bessie can have on that roller coaster without exceeding her dizziness limit. Print each integer on its own line with no spaces. Do not print any blank lines between answers.
Ліміт часу 15 секунд
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3 1 2
2 1
3 1
5 2
4 1 1
2 1
3 1
2 2
3 3
0 0 0
Вихідні дані #1
7
3