View Code of Problem 61

#include<iostream> 
#include <stdio.h>
#include <math.h>
#include "string.h"
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n-i-1;j++){
				if(a[j]>a[j+1]){
					swap(a[j],a[j+1]);
				}
			}
		}
		int max=0;
		for(int i=0;i<n;i++){
			int sum=a[i]*(n-i);
			if(max<sum){
				max=sum;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 61