QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556777 | #8586. Party | allaeben | 0 | 1ms | 3720kb | C++14 | 979b | 2024-09-10 20:53:43 | 2024-09-10 20:53:44 |
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;
int finalSum = 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];
}
finalSum = sum1;
} 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
finalSum = max(sum1, sum2);
}
// Check if the final sum is negative
if (finalSum < 0) {
finalSum = 0;
}
cout << finalSum << 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: 3648kb
input:
5 3 2 -1 4 5
output:
12
result:
ok single line: '12'
Test #2:
score: 49
Accepted
time: 0ms
memory: 3716kb
input:
1 10
output:
10
result:
ok single line: '10'
Test #3:
score: 49
Accepted
time: 0ms
memory: 3640kb
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: 49
Accepted
time: 0ms
memory: 3644kb
input:
3 -545682056 -357195145 -896022492
output:
0
result:
ok single line: '0'
Test #6:
score: 49
Accepted
time: 0ms
memory: 3636kb
input:
1 -985752471
output:
0
result:
ok single line: '0'
Test #7:
score: 49
Accepted
time: 0ms
memory: 3564kb
input:
3 -967312074 -806740862 -470454688
output:
0
result:
ok single line: '0'
Test #8:
score: 49
Accepted
time: 0ms
memory: 3632kb
input:
1 -678590920
output:
0
result:
ok single line: '0'
Test #9:
score: 49
Accepted
time: 0ms
memory: 3700kb
input:
3 -834395995 -25305488 -737371170
output:
0
result:
ok single line: '0'
Test #10:
score: 49
Accepted
time: 0ms
memory: 3636kb
input:
3 -625738487 -887456200 -987524262
output:
0
result:
ok single line: '0'
Test #11:
score: 49
Accepted
time: 0ms
memory: 3640kb
input:
2 -661080051 -932593576
output:
0
result:
ok single line: '0'
Test #12:
score: 49
Accepted
time: 0ms
memory: 3720kb
input:
3 -24484201 -935713814 -995951389
output:
0
result:
ok single line: '0'
Test #13:
score: 49
Accepted
time: 1ms
memory: 3644kb
input:
3 -613085470 -751971711 -524347282
output:
0
result:
ok single line: '0'
Test #14:
score: 49
Accepted
time: 0ms
memory: 3648kb
input:
3 -654382514 -667516785 -950616750
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
39 180058710 -674282733 -438168020 -260398973 -805610545 106322236 -712433626 -944699828 -736674441 -779854452 -801894165 464695032 -278136596 -631401745 -205171008 -17364329 -742867022 -113083080 -760516811 -868233377 -789746133 -734031924 56426842 -848409488 -499938114 -567466530 -994156886 -24223...
output:
1010682883
result:
wrong answer 1st lines differ - expected: '933026007', found: '1010682883'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%