eolymp
bolt
Try our new interface for solving problems
Məsələlər

Loan Scheduling

Loan Scheduling

The North Pole Beach Bank has to decide upon a set App of mortgage applications. Each application \textit{a}∈\textit{App} has an acceptance deadline \textit{d_a}, ie. the required loan must be paid at a time \textit{t_a}, 0≤\textit{t_a}≤\textit{d_a}. If the application is accepted the Bank gets a profit \textit{p_a}. Time is measured in integral units starting from the conventional time origin 0, when the Bank decides upon all the \textit{App} applications. Moreover, the Bank can pay a maximum number of \textit{L} loans at any given time. The Bank policy if focussed solely on profit: it accepts a subset \textit{S}⊆\textit{App} of applications that maximizes the profit . The problem is to compute the maximum profit the Bank can get from the given set \textit{App} of mortgage applications. For example, consider that \textit{L=1}, \textit{App=\{a,b,c,d\}}, \textit{(p_a,d_a)=(4,2)}, \textit{(p_b,d_b)=(1,0)}, \textit{(p_c,d_c)=(2,0)}, and \textit{(p_d,d_d)=(3,1)}. The table below shows all possible sets of accepted mortgage applications and the scheduling of the loan payments. The highest profit is \textit{9} and corresponds to the set \textit{\{c,d,a\}}. The loan requested by the application \textit{c} is paid at time \textit{0}, the loan corresponding to \textit{d} is paid at time \textit{1}, and, finally, the loan of \textit{a} is paid at time \textit{2}. \InputFile Write a program that reads sets of data from an input text file. Each data set corresponds to a set of mortgage applications and starts with two integers: \textit{0≤N≤10000} that shows the number of applications in the set, and \textit{0≤L≤100} which shows the maximum number of loans the Bank can pay at any given time. Follow \textit{N} pairs of integers \textit{p_i} \textit{d_i}, \textit{i=1..N}, that specify the profit \textit{0≤p_i≤10000} and the deadline \textit{0≤d_i≤10000} of the application \textit{i}. Input data are separated by white spaces, are correct, and terminate with an end of file. \OutputFile For each data set the program computes the maximum profit the Bank can get from the accepted mortgage applications corresponding to that data set. The result is printed on standard output from the beginning of a line. There must be no empty lines on output. An example of input/output is shown below.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
4 1     4 2  1 0   2 0    3 1

7 2
200 1   200 1   100 0   1000 2    80 1
50 20   500 1

0 100

1 0     4 1000
Çıxış verilənləri #1
9
2050
0
0
Mənbə Southeastern Europe 2007