Input
The first line of the input file 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 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.
Sample Input
2
3
10 1 15
2
10 15
Sample Output
20
20
Source: Asia - Tehran 2003
my code:
#include <iostream>
#include <string>
using namespace std;
void sel_sort(int p[],int size){
for(int i=0;i<size-1;i++){
int lc=i;
for(int j=i+1;j<size;j++){
if(p[lc]<p[j]){
lc=j;
}
}
swap(p[lc],p[i]);
}
}
int main(){
int n,k;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&k);
int *t=new int [k];
for(int j=0;j<k;j++){
scanf("%d",&t[j]);
}
sel_sort(t,k);
int *nt=new int [k];
for(int j=0;j<k;j++){
nt[j]=(j+1)*t[j];
}
sel_sort(nt,k);
cout<<nt[0]<<endl;
delete []t;
delete []nt;
}
return 0;
}