-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunyou.cpp
42 lines (38 loc) · 914 Bytes
/
chunyou.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
static bool cmp (int a, int b) {
return a < b;
}
int solve (vector<int>& num, int size, int &result) {
if(size == 1) return num[0];
if(size == 2) return max(num[0], num[1]);
if(size == 3) return num[0] + num[1] + num[2];
sort(num.begin(), num.end(), cmp);
int i = 1;
for (; i < size ; i++) {
result += num[i];
}
result += (size - 2) * num[0];
return result;
}
};
int main (void) {
int t, i = 0, n, tem;
cin>>t;
vector<int>nums;
for(; i < t; i++){
cin>>n;
int result = 0;
while(n--){
cin>>tem;
nums.push_back(tem);
}
Solution s;
s.solve(nums, nums.size(), result);
nums.clear();
cout<<result<<endl;
}
return 0;
}