HDU2803 The MAX 【水题】

来源:互联网 发布:网达软件 编辑:程序博客网 时间:2024/05/02 04:24

http://acm.hdu.edu.cn/showproblem.php?pid=2803


 

Problem Description
Giving N integers, V1, V2,,,,Vn, you should find the biggest value of F.
 

Input
Each 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.
 

Output
For each test case, output the biggest value of F you can find on a line.
 

Sample Input
2
1 2
0
 

Sample Output
4017
 

AC代码:

#include <cstdio>#include <algorithm>using namespace std;long long a[110];int main(){    int N;    while(~scanf("%d",&N),N)    {        for(int i=0;i<N;++i)        {            scanf("%lld",a+i);        }        sort(a,a+N);        long long res=0;        for(int i=0;i<N-1;++i)                        res+=a[i];            res+=a[N-1]*(2009-N+1);        printf("%lld\n",res);            }    return 0;}


0 0
原创粉丝点击