The MAX

Giving N integers, V1, V2,,,,Vn, you should find the biggest value of F. 
InputEach test case contains a single integer N (1<=N<=100). The next line contains N integers, meaning the value of V1, V2....Vn.(1<= Vi <=10^8).The input is terminated by a set starting with N = 0. This set should not be processed.OutputFor each test case, output the biggest value of F you can find on a line.Sample Input
2
1 2
0
Sample Output
4017
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long sum[150];
bool cmp(int a,int b){
	return a>b;
}
int main(){
	long long N,he;
	while(scanf("%lld",&N)!=EOF){
		if(N==0) break;
		for(int i=0;i<N;i++){
			scanf("%lld",&sum[i]);
		}
		sort(sum,sum+N,cmp);
		he=sum[0]*(2010-N);
		for(int i=1;i<N;i++){
			he+=sum[i];
		}
		printf("%lld\n",he);
	}
	return 0;
}//注意数据的范围我把int都改成longlong才过的

猜你喜欢

转载自blog.csdn.net/miku531/article/details/79334151
max