Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12585 | Accepted: 4787 |
Description
Input
Output
Sample Input
1
4
1 2 5 10
Sample Output
17
Source
<span style="font-size:18px;">#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; #define ll long long #define CL(a,b) memset(a,b,sizeof(a)) #define MAXN 100010 int T,n; int a[1010]; int sum; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); CL(a, 0); for(int i=0; i<n; i++) scanf("%d",&a[i]); if(n == 1){printf("%d\n",a[0]); continue;} sort(a, a+n); int m1 = a[0], m2 = a[1]; sum = 0; for(int i=n-1; i>1; i-=2) { if(m2*2<m1+a[i-1]) { if(i == 2) sum = sum+m1+m2+a[i]; else sum = sum+m1+m2*2+a[i]; } else { sum = sum+m1*2+a[i]+a[i-1]; if(i == 2) sum -= a[0]; } } if(n!=0&&n%2==0) sum += m2; printf("%d\n",sum); } return 0; } </span>
原文:http://www.cnblogs.com/zhchoutai/p/7363111.html