| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么错阿#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int n;
int i;
int num[1001];
while(scanf("%d", &n) != EOF)
{
int ans = 0;
for(i = 0; i < n; i++)
scanf("%d", &num[i]);
sort(num, num+n);
int f1 = num[0], f2 = num[1];
int s1 = num[n-1], s2 = num[n-2];
while(n != 0)
{
if(n == 1 || n == 2) {ans += s1; break;}
if(n == 3) {ans += s2+s1+f1; break;}
else if(n >= 4)
{
if(2*f2 >= f1+s2){ans += (2*f1+s1+s2);n -= 2; s1 = num[n-1]; s2 = num[n-2];}
else {ans += (2*f2+f1+s1); n -= 2; s1 = num[n-1]; s2 = num[n-2];}
}
}
printf("%d\n", ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator