#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
#define endl ('\n')
using namespace std;
void solve() {
int n;
cin>>n;
vector<int>x(n);
vector<int>y;
int res=0;
for(int i=0;i<n;i++){
cin>>x[i];
}
if(n==1){
cout<<0<<endl;
return;
}
sort(x.begin(),x.end());
y.push_back(x[n-1]);
for(int i=0;i<n-1;i++){
y.push_back(x[i]);
}
for(int i=0;i<n-1;i++){
res+=(y[i]+y[i+1]);
}
cout<<res<<endl;
}
int32_t main(){
fast
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
2268 KB |
Output is correct |
3 |
Correct |
9 ms |
2268 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
9 ms |
2400 KB |
Output is correct |
6 |
Correct |
10 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
2268 KB |
Output is correct |
3 |
Correct |
9 ms |
2268 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
9 ms |
2400 KB |
Output is correct |
6 |
Correct |
10 ms |
2156 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |