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

Flight Boarding Optimization

Flight Boarding Optimization

Peter is an executive boarding manager in Byteland airport. His job is to optimize the boarding process. The planes in Byteland have \textbf{s} rows, numbered from \textbf{1} to \textbf{s}. Every row has six seats, labeled \textbf{A} to \textbf{F}. \includegraphics{https://static.e-olymp.com/content/f9/f9260d420f1d1f441321ed2fb9363d3b06a0d1c6.jpg} There are \textbf{n} passengers, they form a queue and board the plane one by one. If the \textbf{i}-th passenger sits in a row \textbf{r_i}then the difficulty of boarding for him is equal to the number of passengers boarded before him and sit in rows \textbf{1...r_i-1}. The total difficulty of the boarding is the sum of difficulties for all passengers. For example, if there are ten passengers, and their seats are \textbf{6A}, \textbf{4B}, \textbf{2E}, \textbf{5F}, \textbf{2A}, \textbf{3F}, \textbf{1C}, \textbf{10E}, \textbf{8B}, \textbf{5A}, in the queue order, then the difficulties of their boarding are \textbf{0}, \textbf{0}, \textbf{0}, \textbf{2}, \textbf{0}, \textbf{2}, \textbf{0}, \textbf{7}, \textbf{7}, \textbf{5}, and the total difficulty is \textbf{23}. To optimize the boarding, Peter wants to divide the plane into k zones. Every zone must be a continuous range of rows. Than the boarding process is performed in k phases. On every phase, one zone is selected and passengers whose seats are in this zone are boarding in the order they were in the initial queue. In the example above, if we divide the plane into two zones: rows \textbf{5--10} and rows \textbf{1--4}, then during the first phase the passengers will take seats \textbf{6A}, \textbf{5F}, \textbf{10E}, \textbf{8B}, \textbf{5A}, and during the second phase the passengers will take seats \textbf{4B}, \textbf{2E}, \textbf{2A}, \textbf{3F}, \textbf{1C}, in this order. The total difficulty of the boarding will be \textbf{6}. Help Peter to find the division of the plane into k zones which minimizes the total difficulty of the boarding, given a specific queue of passengers. \InputFile The first line contains three integers \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{1000}), \textbf{s} (\textbf{1} ≤ \textbf{s} ≤ \textbf{1000}), and \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{50}, \textbf{k} ≤ \textbf{s}). The next line contains \textbf{n} integers \textbf{r_i} (\textbf{1} ≤ \textbf{r_i} ≤ \textbf{s}). Each row is occupied by at most \textbf{6} passengers. \OutputFile Output one number, the minimal possible difficulty of the boarding.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
10 12 2
6 4 2 5 2 3 1 11 8 5
Çıxış verilənləri #1
6
Mənbə ACM ICPC 2013–2014, NEERC, Northern Subregional Contest, St Petersburg, October 26, 2013