View Code of Problem 61

#include<stdio.h>
int main(){
	int t,n,temp,weight,max;
	while(scanf("%d",&t)!=EOF){
		while(t--){
			scanf("%d",&n);
			int rope[n];
			for(int i=0;i<n;i++){
				scanf("%d",rope+i);
			}
			for(int i=0;i<n;i++){
				for(int j=0;j<n-1-i;j++){
					if(rope[j]>rope[j+1]){
						temp=rope[j];
						rope[j]=rope[j+1];
						rope[j+1]=temp;
					}
				}
			}
			for(int i=0;i<n;i++){
				rope[i]=rope[i]*(n-i);
			}
			max=0;
			for(int i=0;i<n;i++){
				if(rope[i]>max){
					max=rope[i];
				}
			}
			printf("%d\n",max);
		}
	}
}

Double click to view unformatted code.


Back to problem 61