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

Rotten Ropes

Rotten Ropes

Suppose we have n ropes of equal length and we want to use them to lift some heavy object. A tear-off weight \textbf{t} is associated to each rope, that is, if we try to lift an object, heavier than \textbf{t} with that rope, it will tear off. But we can fasten a number of ropes to the heavy object (in parallel), and lift it with all the fastened ropes. When using \textbf{k} ropes to lift a heavy object with weight \textbf{w}, we assume that each of the \textbf{k} ropes, regardless of its tear-off weight, is responsible for lifting a weight of \textbf{w/k}. However, if \textbf{w/k} > \textbf{t} for some rope with tear-off weight of \textbf{t}, that rope will tear off. For example, three ropes with tear-off weights of \textbf{1}, \textbf{10}, and \textbf{15}, when all three are fastened to an object, can not lift an object with weight more than \textbf{3}, unless the weaker one tears-off. But the second rope, may lift by itself, an object with weight at most \textbf{10}. Given the tear-off weights of \textbf{n} ropes, your task is to find the weight of the heaviest object that can be lifted by fastening a subset of the given ropes without any of them tearing off. \InputFile The first line of the input file contains a single integer \textbf{t} (\textbf{1} ≤ \textbf{t} ≤ \textbf{10}), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{1000}) which is the number of ropes. Following the first line, there is a single line containing \textbf{n} integers between \textbf{1} and \textbf{10000} which are the tear-off weights of the ropes, separated by blank characters. \OutputFile Each line of the output file should contain a single number, which is the largest weight that can be lifted in the corresponding test case without tearing off any rope chosen.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
2
3
10 1 15
2
10 15
Выходные данные #1
20
20