#include <iostream>
#include <algorithm>
using namespace std;
long long n,i,c[100010],s;
int main() {
cin>>n;
for (i=1;i<=n;i++)
cin>>c[i];
sort(c+1,c+n+1);
for (i=n;i>=1;i--) {
s+=c[i];
if (n%3==0) {
if (i%3==1)
s-=c[i];
}
else if (n%3==1) {
if (i%3==2)
s-=c[i];
}
else if (n%3==2) {
if (i%3==0)
s-=c[i];
}
}
cout<<s;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
44 ms |
1220 KB |
Output is correct |
7 |
Correct |
40 ms |
1144 KB |
Output is correct |
8 |
Correct |
40 ms |
1132 KB |
Output is correct |
9 |
Correct |
66 ms |
1144 KB |
Output is correct |
10 |
Correct |
59 ms |
1144 KB |
Output is correct |