#include <bits/stdc++.h>
using namespace std;
const int N=1e5+55;
int a[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
long long ans=0;
for(int i=n-1;i>=0;i--)
{
if(i>=2)
{
ans+=a[i];
i--;
ans+=a[i];
i--;
}
else
ans+=a[i];
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
2 ms |
524 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
30 ms |
1392 KB |
Output is correct |
7 |
Correct |
33 ms |
1908 KB |
Output is correct |
8 |
Correct |
26 ms |
2296 KB |
Output is correct |
9 |
Correct |
41 ms |
2960 KB |
Output is correct |
10 |
Correct |
42 ms |
3388 KB |
Output is correct |