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

Supermarket

Supermarket

\includegraphics{https://static.e-olymp.com/content/a0/a01d6fe5baf86fd274dfc5600a30f76cc672dd3c.jpg} A supermarket has a set \textbf{Prod} of products on sale. It earns a profit \textbf{p_x} for each product \textbf{x} \textbf{Prod} sold by a deadline\textbf{d_x} that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. \includegraphics{https://static.e-olymp.com/content/17/17036a020b88689c250b155e7cf491dca420724a.jpg} \includegraphics{https://static.e-olymp.com/content/a0/a01d6fe5baf86fd274dfc5600a30f76cc672dd3c.jpg} \includegraphics{https://static.e-olymp.com/content/e7/e74d54278784e28fb95028ce0b789b99745a4d4f.jpg} A selling schedule is an ordered subset of products \textbf{Sell} \textbf{Prod} such that the selling of each product x \textbf{Sell}, according to the ordering of \textbf{Sell}, completes before the deadline \textbf{d_x} or just when \textbf{d_\{x \}}expires. The profit of the selling schedule is Profit(Sell) = _\{x \}\textbf{_Sell p_x}. An optimal selling schedule is a schedule with a maximum profit. \includegraphics{https://static.e-olymp.com/content/97/977845ad37c49a01ad2da140e47490b47753f22a.jpg} For example, consider the products \textbf{Prod=\{a,b,c,d\}} with \textbf{(p_a,d_a=(50,2)}, \textbf{(p_b,d_b)=(10,1)},\textbf{(p_c,d_c)=(20,2)}, and \textbf{(p_c,p_d)=(30,1)}. The possible selling schedules are listed in table 1. For instance, the schedule \textbf{Sell=\{d,a\}} shows that the selling of product \textbf{d} starts at time \textbf{0 }and ends at time \textbf{1}, while the selling of product a starts at time \textbf{1} and ends at time \textbf{2}. Each of these products is sold by its deadline. \textbf{Sell} is the optimal schedule and its profit is \textbf{80}. Write a program that reads sets of products from an input text file and computes the profit of an optimal selling schedule for each set of products. \InputFile A set of products starts with an integer \textbf{0} ≤ \textbf{n} ≤ \textbf{10000}, which is the number of products in the set, and continues with \textbf{n} pairs \textbf{p_i d_i} of integers, \textbf{1} ≤ \textbf{p_i} ≤ \textbf{10000} and \textbf{1} ≤ \textbf{d_i} ≤ \textbf{10000}, that designate the profit and the selling deadline of the \textbf{i}-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct. \OutputFile For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4 50 2 10 1 20 2 30 1
7 20 1 2 1 10 3 100 2 8 2 5 20 50 10
Выходные данные #1
80
185
Источник ACM ICPC Southeastern European Regional Programming Contest, Bucharest, Romania, October 18, 2003