Submission #818122

# Submission time Handle Problem Language Result Execution time Memory
818122 2023-08-10T02:34:01 Z BamshooT Feast (NOI19_feast) C++14
45 / 100
26 ms 26836 KB
#include <iostream>
#include <algorithm>
#include <cstring>

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ll long long
#define inf 1e18

using namespace std;

struct dt{
    ll t, c;
    bool operator < (const dt &x) const{
        return (t > x.t);
    }
};

const int N = 3e5 + 9;
int n, k, t;
ll dp[2009][2009], a[N], pre[N];

void solve(){
    int p;
    ll s = 0;
    FOR(i, 1, n) {
        s += a[i];
        if (a[i] < 0) p = i;
    }
    cout << s - a[p];
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //  freopen("nhap.inp", "r", stdin);
  //  freopen("xuat.out", "w", stdout);
    cin >> n >> k;
    FOR(i, 1, n) {
        cin >> a[i];
        t += (a[i] < 0);
        pre[i] = pre[i-1] + a[i];
    }
    if (t == 0){
        cout << pre[n]; return 0;
    }
    if (t == 1 && k > 1) {
        solve();
        return 0;
    }
    FOR(i, 1, k) {
        ll cur = 0;
        FOR(j, 1, n) {
            cur = max(cur, dp[i-1][j] - pre[j]);
            dp[i][j] = max(dp[i][j-1], pre[j] + cur);
        }
    }
    cout <<dp[k][n];
    return 0;
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:29:20: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |     cout << s - a[p];
      |                 ~~~^
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4820 KB Output is correct
2 Correct 25 ms 7704 KB Output is correct
3 Correct 25 ms 7812 KB Output is correct
4 Correct 25 ms 7768 KB Output is correct
5 Correct 25 ms 7768 KB Output is correct
6 Correct 25 ms 7668 KB Output is correct
7 Correct 24 ms 7592 KB Output is correct
8 Correct 24 ms 7808 KB Output is correct
9 Correct 24 ms 7652 KB Output is correct
10 Correct 24 ms 7712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 7124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 724 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 596 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 724 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 596 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 13 ms 26836 KB Output is correct
23 Correct 3 ms 6356 KB Output is correct
24 Correct 3 ms 3668 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 3 ms 4676 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4820 KB Output is correct
2 Correct 25 ms 7704 KB Output is correct
3 Correct 25 ms 7812 KB Output is correct
4 Correct 25 ms 7768 KB Output is correct
5 Correct 25 ms 7768 KB Output is correct
6 Correct 25 ms 7668 KB Output is correct
7 Correct 24 ms 7592 KB Output is correct
8 Correct 24 ms 7808 KB Output is correct
9 Correct 24 ms 7652 KB Output is correct
10 Correct 24 ms 7712 KB Output is correct
11 Incorrect 16 ms 7124 KB Output isn't correct
12 Halted 0 ms 0 KB -