Submission #17990584


Source Code Expand

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

using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i,j,n) for (ll i = j; i < (ll)(n); ++i)

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    vector<ll> B(N, 0);
    vector<ll> B_max_i(N, 0);
    B.at(0) = A.at(0);
    rep2(i, 1, N) B.at(i) = A.at(i) + B.at(i-1);
    ll max_i=0;
    ll max_sum=0;
    rep(i, N){
        if(chmax(max_sum, B.at(i))){
            max_i = i;
        }
        B_max_i.at(i) = max_i;
    }

    ll ans = 0;
    ll sum = 0;
    rep(i,N){
        chmax(ans, sum+B.at(B_max_i.at(i)));
        sum += B.at(i);
    }

    cout << ans << endl;
}

Submission Info

Submission Time
Task D - Wandering
User papino
Language C++ (GCC 9.2.1)
Score 400
Code Size 888 Byte
Status AC
Exec Time 77 ms
Memory 8004 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All around0_00.txt, around0_01.txt, around0_02.txt, around0_03.txt, around0_04.txt, around0_05.txt, extreme_00.txt, extreme_01.txt, handmade_00.txt, handmade_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
around0_00.txt AC 73 ms 7780 KiB
around0_01.txt AC 69 ms 7772 KiB
around0_02.txt AC 72 ms 7852 KiB
around0_03.txt AC 42 ms 5136 KiB
around0_04.txt AC 7 ms 3680 KiB
around0_05.txt AC 63 ms 6896 KiB
extreme_00.txt AC 73 ms 7796 KiB
extreme_01.txt AC 74 ms 7824 KiB
handmade_00.txt AC 3 ms 3592 KiB
handmade_01.txt AC 2 ms 3408 KiB
random_00.txt AC 77 ms 7776 KiB
random_01.txt AC 72 ms 8004 KiB
random_02.txt AC 71 ms 7916 KiB
random_03.txt AC 69 ms 7960 KiB
random_04.txt AC 7 ms 3780 KiB
random_05.txt AC 62 ms 6864 KiB
random_06.txt AC 9 ms 3728 KiB
random_07.txt AC 50 ms 6064 KiB
sample_01.txt AC 3 ms 3416 KiB
sample_02.txt AC 2 ms 3624 KiB
sample_03.txt AC 2 ms 3596 KiB