Submission details
Task:Maximum sum
Sender:aalto26cm_044
Submission time:2026-09-14 16:57:30 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#6ACCEPTED0.02 sdetails
#70.02 sdetails
#80.03 sdetails
#90.04 sdetails
#100.04 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:8: warning: unused variable 'val' [-Wunused-variable]
   37 |     ll val = -1000000;
      |        ^~~

Code

#include <bits/stdc++.h>
using namespace std;

#define all(x)  begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x)   (int)(x).size()                                 // signed size: avoids the unsigned .size() wrap bug

using ll  = long long;
using pii = pair<int,int>;
using vi  = vector<int>;

#ifdef LOCAL                                                    // compile with -DLOCAL to enable, silent on the judge
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] = ", dbg_out(__VA_ARGS__)
template<class T> void dbg_out(T x) { cerr << x << '\n'; }
template<class T, class... R> void dbg_out(T x, R... r) { cerr << x << ", "; dbg_out(r...); }
#else
#define dbg(...)
#endif

int main() {
    cin.tie(0)->sync_with_stdio(0);                             // never mix with scanf/printf after this
    int n; cin >> n; 
    // int n,m; cin >> n >> m; 
    vi a(n); for (auto &x : a) cin >> x;

    vector<ll> s(n+1, 0);
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
        s[i+1] = sum;
    }

    ll out = -1000000;

    int i = 0, j = 0;
    ll val = -1000000;
    while (i <= n && j <= n)
    {

        if (a[j] >= -a[i] || i == j || j > n){
            j += 1;
        } else{
            i += 1;
        }
        ll v1 = s[j] - s[i];
        // cout << v1 << " "<< i <<" "<<  j<< "\n";
        out = max(out, v1);

    }
    
    





    cout << out;
    return 0;
}

Test details

Test 1

Verdict:

input
10
1 1 1 1 1 1 1 1 1 1

correct output
10

user output
101489

Feedback: Incorrect character on line 1 col 3: expected "10", got "101489"

Test 2

Verdict:

input
10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

correct output
-1

user output
101498

Feedback: Incorrect character on line 1 col 1: expected "-1", got "101498"

Test 3

Verdict:

input
10
24 7 -27 17 -67 65 -23 58 85 -...

correct output
185

user output
101535

Feedback: Incorrect character on line 1 col 2: expected "185", got "101535"

Test 4

Verdict:

input
10
99 -59 31 83 -79 64 -20 -87 40...

correct output
154

user output
101489

Feedback: Incorrect character on line 1 col 2: expected "154", got "101489"

Test 5

Verdict:

input
10
-19 61 60 33 67 19 -8 92 59 -3...

correct output
383

user output
101508

Feedback: Incorrect character on line 1 col 1: expected "383", got "101508"

Test 6

Verdict: ACCEPTED

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
200000

user output
200000

Test 7

Verdict:

input
200000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
-1

user output
200000

Feedback: Incorrect character on line 1 col 1: expected "-1", got "200000"

Test 8

Verdict:

input
200000
381082742 830199996 -85684827 ...

correct output
231210956017

user output
123321735426

Feedback: Incorrect character on line 1 col 1: expected "231210956017", got "123321735426"

Test 9

Verdict:

input
200000
-935928962 -795492223 75287481...

correct output
184607318819

user output
251043488841

Feedback: Incorrect character on line 1 col 1: expected "184607318819", got "251043488841"

Test 10

Verdict:

input
200000
524408131 613017181 -62281009 ...

correct output
360019999220

user output
216789370903

Feedback: Incorrect character on line 1 col 1: expected "360019999220", got "216789370903"

Test 11

Verdict: ACCEPTED

input
1
1

correct output
1

user output
1

Test 12

Verdict:

input
1
-2

correct output
-2

user output
2

Feedback: Incorrect character on line 1 col 1: expected "-2", got "2"

Test 13

Verdict:

input
5
-1 -1 -1 -1 -2

correct output
-1

user output
6

Feedback: Incorrect character on line 1 col 1: expected "-1", got "6"

Test 14

Verdict:

input
2
-3 -2

correct output
-2

user output
101574

Feedback: Incorrect character on line 1 col 1: expected "-2", got "101574"

Test 15

Verdict:

input
1
-1000000000

correct output
-1000000000

user output
1000000000

Feedback: Incorrect character on line 1 col 1: expected "-1000000000", got "1000000000"