QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556776 | #8586. Party | allaeben | 0 | 0ms | 3712kb | C++14 | 833b | 2024-09-10 20:52:10 | 2024-09-10 20:52:10 |
answer
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
// Sort the array
sort(arr, arr + n);
int sum1 = 0, sum2 = 0;
if (n % 2 == 0) {
// If n is even, take the last n % 2 elements
for (int i = n - (n /2); i < n; ++i) {
sum1 += arr[i];
}
cout << sum1 << endl;
} else {
// If n is odd, calculate both sums
for (int i = n - (((n - 1) /2 )+ 1); i < n; ++i) {
sum1 += arr[i];
}
for (int i = n - ((n - 1) / 2); i < n; ++i) {
sum2 += arr[i];
}
// Output the largest sum
cout << max(sum1, sum2) << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 49
Accepted
time: 0ms
memory: 3712kb
input:
5 3 2 -1 4 5
output:
12
result:
ok single line: '12'
Test #2:
score: 49
Accepted
time: 0ms
memory: 3572kb
input:
1 10
output:
10
result:
ok single line: '10'
Test #3:
score: 49
Accepted
time: 0ms
memory: 3576kb
input:
6 1 -3 2 10 -4 9
output:
21
result:
ok single line: '21'
Test #4:
score: 49
Accepted
time: 0ms
memory: 3640kb
input:
1 -983826926
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 3636kb
input:
3 -545682056 -357195145 -896022492
output:
-357195145
result:
wrong answer 1st lines differ - expected: '0', found: '-357195145'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%