2291 Rotten Ropes
来源:互联网 发布:手机广告屏蔽软件 编辑:程序博客网 时间:2024/05/20 03:07
Description
Suppose we have n ropes of equal length and we want to use them to lift some heavy object. A tear-off weight t is associated to each rope, that is, if we try to lift an object, heavier than 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 k ropes to lift a heavy object with weight w, we assume that each of the k ropes, regardless of its tear-off weight, is responsible for lifting a weight of w/k. However, if w/k > t for some rope with tear-off weight of t, that rope will tear off. For example, three ropes with tear-off weights of 1, 10, and 15, when all three are fastened to an object, can not lift an object with weight more than 3, unless the weaker one tears-off. But the second rope, may lift by itself, an object with weight at most 10. Given the tear-off weights of 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.
Input
The first line of the input contains a single integer t (1 <= t <= 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 n (1 <= n <= 1000) which is the number of ropes. Following the first line, there is a single line containing n integers between 1 and 10000 which are the tear-off weights of the ropes, separated by blank characters.
Output
Each line of the output 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.
Sample Input
2
3
10 1 15
2
10 15
Sample Output
20
20
Source
Tehran 2003
/*给出n根承重不同的绳子,选出几根使得承重最大且没有绳子断裂*/#include<iostream>#include<algorithm>using namespace std;bool cmp(int a, int b){ return a > b;}int main(){ int t; cin >> t; while (t--) { int n; int w[10000]; int max[1000] = { 0 }; cin >> n; for (int i = 0; i < n; i++) { cin >> w[i]; } sort(w, w + n, cmp); for (int i = 0; i < n; i++) { max[i] = (i + 1)*w[i]; } sort(max, max + n, cmp); cout << max[0] << endl; } return 0;}
- 2291 Rotten Ropes
- POJ 2291 Rotten Ropes G++
- Rotten Ropes
- zoj 2488 || poj 2291 Rotten Ropes
- zoj 2488 Rotten Ropes
- ZOJ 2488 Rotten Ropes
- ZOJ-2488 Rotten Ropes
- hdu——Rotten Ropes
- UVa10985 Rings'n'Ropes
- Chain the Ropes
- Tokyo Westerns/MMA CTF - Rotten Uploader
- Ropes:an alternative to strings
- uva 10952 Rings'n'Ropes
- 1125. Chain the Ropes (25)
- PAT--1125. Chain the Ropes
- 1125. Chain the Ropes 解析
- PAT A1125 Chain the Ropes
- pat-aChain the Ropes (25)
- hdu4355Party All the Time(三分查找模板题)
- [ZOJ] 4257 Most Powerful [状压DP]
- 【IT观察】作为一个DBA,如何选择数据库
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
- 一个js展示日历的插件
- 2291 Rotten Ropes
- 进制转换
- python获取代理(终极版本)
- 如何成为更好的自己
- 代写演讲稿的7步骤
- 记即将30的我,测试野路子
- [tensorflow损失函数系列]sigmoid_cross_entropy_with_logits
- 梯度下降优化算法综述
- SDE写入矢量与栅格