View Code of Problem 61

#include<bits/stdc++.h>
using namespace std;                          
    
/*1 2 4 
1 10 15
 5 7 1 6 9 10    1 5 6 7 9 10

若将n根绳子扭在一起来吊起一个重量为w的物体,那每根绳子所承受的重量为w/n
*/          
int main(){      
	 int n,m,a[1000] = { },max,op;
	 cin>>n;
	 for(int u = 0; u<n;u++){
	 	cin>>m;
	 	for(int i = 0;i<m;i++)cin>>a[i];
	 	sort(a,a+m);
	 	max = a[0]*m;
	 	for(int i = 1;i<m;i++){
	 		op = a[i]*(m-i);
	 		if(op>max) max = op;
		 }
	 	cout<<max<<endl;	
	 }  
	
	        
	return 0;
}

Double click to view unformatted code.


Back to problem 61