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

Sorting

We have an array and we want to sort it in non-decreasing order. The only allowable operation is to move one element of the array into any other place (before all elements, after all elements or between any two adjacent elements). The cost of the single operation is equal to the value of the moved element. We want to minimize the total cost of sorting the array. You are to write a program that will find the minimum cost to sort such an array. \InputFile First line of the input contains \textbf{T} the number of test cases. For each test case the first line contains an integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}). The second line contains \textbf{N} positive integers separated by spaces. These integers denote the array. Each of these integers is between \textbf{1} and \textbf{1000} inclusive. \OutputFile For each case, the output contains an integer denoting the minimum cost to sort the array.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3
4
7 1 2 3
4
7 1 2 5
6
8 2 6 5 1 4
Вихідні дані #1
6
7
18
Джерело ACM-ICPC Malaysia al-Khawārizmī Programming Contest 2011