Submission #1000311

# Submission time Handle Problem Language Result Execution time Memory
1000311 2024-06-17T08:30:50 Z nngan267 Feast (NOI19_feast) C++17
71 / 100
1000 ms 31260 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define db long double
#define ii pair<int, int>
#define fi first
#define se second

const int maxn = 3e5+5;
const ll mod = 111539786;
const db eps = -1e9;
const ll inf = 1e18;


int n, k;
int a[maxn];
ll dp[2005][2005];
ll s[maxn];

struct sub1{
    ll sum = 0;
    void solve(){
        for(int i=1; i<=n; i++){
            sum += a[i];
        }
        cout << sum << "\n";
    }
} s1;

struct sub2{
    void solve(){
        int pos = 0;
        for(int i=1; i<=n; i++){
            if(a[i] < 0) pos = i;
        }
        ll sum1 = 0, sum2 = 0;
        for(int i=1; i<pos; i++){
            sum1 += a[i];
        }
        for(int i=pos+1; i<=n; i++){
            sum2 += a[i];
        }
        if(k == 1) cout << max({sum1, sum2, sum1+sum2+a[pos]});
        else{
            cout << sum1 + sum2 << "\n";
        }
    }
} s2;

struct sub3{
    void solve(){
        ll min_val = 0;
        ll ans = 0;
        for(int i=1; i<=n; i++){
            ans = max(ans, s[i] - min_val);
            min_val = min(min_val, s[i]);
        }
        cout << ans << "\n";
    }
} s3;

struct sub4{
    void solve(){
        for(int i=1; i<=k; i++){
            ll max_val = 0;
            for(int j=1; j<=n; j++){
                dp[i][j] = dp[i][j-1];
                dp[i][j] = max(dp[i][j], max_val + s[j]);
                max_val = max(max_val, dp[i-1][j] - s[j]);
            }
        }
        cout << dp[k][n] << "\n";
    }
} s4;

bool checks1(){
    int min_val = a[1];
    for(int i=2; i<=n; i++){
        min_val = min(min_val, a[i]);
    }
    return min_val >= 0;
}

bool checks2(){
    int cnt = 0;
    for(int i=1; i<=n; i++){
        if(a[i] < 0) cnt++;
    }
    return cnt <= 1;
}

bool checks3(){
    return k == 1;
}

void solve(){
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        s[i] = s[i-1] + a[i];
    }
    if(checks1()) s1.solve();
    else if(checks2()) s2.solve();
    else if(checks3()) s3.solve();
    else s4.solve();
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    while(test--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 8540 KB Output is correct
2 Correct 22 ms 8540 KB Output is correct
3 Correct 22 ms 8780 KB Output is correct
4 Correct 22 ms 8540 KB Output is correct
5 Correct 22 ms 8532 KB Output is correct
6 Correct 22 ms 8528 KB Output is correct
7 Correct 21 ms 8528 KB Output is correct
8 Correct 22 ms 8528 KB Output is correct
9 Correct 20 ms 8540 KB Output is correct
10 Correct 23 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 7004 KB Output is correct
2 Correct 26 ms 6840 KB Output is correct
3 Correct 13 ms 7004 KB Output is correct
4 Correct 14 ms 6828 KB Output is correct
5 Correct 22 ms 8528 KB Output is correct
6 Correct 14 ms 7004 KB Output is correct
7 Correct 13 ms 7060 KB Output is correct
8 Correct 22 ms 8712 KB Output is correct
9 Correct 21 ms 8528 KB Output is correct
10 Correct 14 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 8792 KB Output is correct
2 Correct 45 ms 8772 KB Output is correct
3 Correct 25 ms 8792 KB Output is correct
4 Correct 26 ms 8784 KB Output is correct
5 Correct 27 ms 8788 KB Output is correct
6 Correct 24 ms 8712 KB Output is correct
7 Correct 26 ms 8940 KB Output is correct
8 Correct 24 ms 8720 KB Output is correct
9 Correct 44 ms 8872 KB Output is correct
10 Correct 31 ms 8768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 13 ms 26972 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 3 ms 6492 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 8540 KB Output is correct
2 Correct 22 ms 8540 KB Output is correct
3 Correct 22 ms 8780 KB Output is correct
4 Correct 22 ms 8540 KB Output is correct
5 Correct 22 ms 8532 KB Output is correct
6 Correct 22 ms 8528 KB Output is correct
7 Correct 21 ms 8528 KB Output is correct
8 Correct 22 ms 8528 KB Output is correct
9 Correct 20 ms 8540 KB Output is correct
10 Correct 23 ms 8788 KB Output is correct
11 Correct 14 ms 7004 KB Output is correct
12 Correct 26 ms 6840 KB Output is correct
13 Correct 13 ms 7004 KB Output is correct
14 Correct 14 ms 6828 KB Output is correct
15 Correct 22 ms 8528 KB Output is correct
16 Correct 14 ms 7004 KB Output is correct
17 Correct 13 ms 7060 KB Output is correct
18 Correct 22 ms 8712 KB Output is correct
19 Correct 21 ms 8528 KB Output is correct
20 Correct 14 ms 7004 KB Output is correct
21 Correct 25 ms 8792 KB Output is correct
22 Correct 45 ms 8772 KB Output is correct
23 Correct 25 ms 8792 KB Output is correct
24 Correct 26 ms 8784 KB Output is correct
25 Correct 27 ms 8788 KB Output is correct
26 Correct 24 ms 8712 KB Output is correct
27 Correct 26 ms 8940 KB Output is correct
28 Correct 24 ms 8720 KB Output is correct
29 Correct 44 ms 8872 KB Output is correct
30 Correct 31 ms 8768 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 13 ms 26972 KB Output is correct
53 Correct 3 ms 8540 KB Output is correct
54 Correct 3 ms 4444 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 2 ms 4444 KB Output is correct
57 Correct 3 ms 6492 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 1 ms 860 KB Output is correct
60 Correct 0 ms 352 KB Output is correct
61 Execution timed out 1084 ms 31260 KB Time limit exceeded
62 Halted 0 ms 0 KB -