QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556789#8586. Partyallaeben0 0ms3688kbC++141.3kb2024-09-10 21:02:112024-09-10 21:02:11

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 21:02:11]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3688kb
  • [2024-09-10 21:02:11]
  • 提交

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) {
            if (sum1 + arr[i] > sum1) {
                sum1 += arr[i];
            } else {
                break;
            }
        }
        finalSum = sum1;
    } else {
        // If n is odd, calculate both sums
        for (int i = n - (((n - 1) / 2) + 1); i < n; ++i) {
            if (sum1 + arr[i] > sum1) {
                sum1 += arr[i];
            } else {
                break;
            }
        }
        for (int i = n - ((n - 1) / 2); i < n; ++i) {
            if (sum2 + arr[i] > sum2) {
                sum2 += arr[i];
            } else {
                break;
            }
        }
        // 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: 3628kb

input:

5
3 2 -1 4 5

output:

12

result:

ok single line: '12'

Test #2:

score: 49
Accepted
time: 0ms
memory: 3500kb

input:

1
10

output:

10

result:

ok single line: '10'

Test #3:

score: 49
Accepted
time: 0ms
memory: 3564kb

input:

6
1 -3 2 10 -4 9

output:

21

result:

ok single line: '21'

Test #4:

score: 49
Accepted
time: 0ms
memory: 3688kb

input:

1
-983826926

output:

0

result:

ok single line: '0'

Test #5:

score: 49
Accepted
time: 0ms
memory: 3600kb

input:

3
-545682056 -357195145 -896022492

output:

0

result:

ok single line: '0'

Test #6:

score: 49
Accepted
time: 0ms
memory: 3684kb

input:

1
-985752471

output:

0

result:

ok single line: '0'

Test #7:

score: 49
Accepted
time: 0ms
memory: 3608kb

input:

3
-967312074 -806740862 -470454688

output:

0

result:

ok single line: '0'

Test #8:

score: 49
Accepted
time: 0ms
memory: 3684kb

input:

1
-678590920

output:

0

result:

ok single line: '0'

Test #9:

score: 49
Accepted
time: 0ms
memory: 3536kb

input:

3
-834395995 -25305488 -737371170

output:

0

result:

ok single line: '0'

Test #10:

score: 49
Accepted
time: 0ms
memory: 3560kb

input:

3
-625738487 -887456200 -987524262

output:

0

result:

ok single line: '0'

Test #11:

score: 49
Accepted
time: 0ms
memory: 3628kb

input:

2
-661080051 -932593576

output:

0

result:

ok single line: '0'

Test #12:

score: 49
Accepted
time: 0ms
memory: 3600kb

input:

3
-24484201 -935713814 -995951389

output:

0

result:

ok single line: '0'

Test #13:

score: 49
Accepted
time: 0ms
memory: 3684kb

input:

3
-613085470 -751971711 -524347282

output:

0

result:

ok single line: '0'

Test #14:

score: 49
Accepted
time: 0ms
memory: 3616kb

input:

3
-654382514 -667516785 -950616750

output:

0

result:

ok single line: '0'

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3688kb

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:

0

result:

wrong answer 1st lines differ - expected: '933026007', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%