답안 #818128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818128 2023-08-10T02:37:38 Z BamshooT Feast (NOI19_feast) C++14
71 / 100
1000 ms 34460 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, p;
ll dp[2009][2009], a[N], pre[N], res, cur;


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);
        if (a[i] < 0) p = i;
        pre[i] = pre[i-1] + a[i];
        res = max(res, pre[i] - cur);
        cur = min(cur, pre[i]);
    }
    if (t == 0){
        cout << pre[n]; return 0;
    }
    if (k == 1) {
        cout << res; return 0;
    }
    if (t == 1) {
        cout << pre[n] - a[p];
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4816 KB Output is correct
2 Correct 27 ms 4908 KB Output is correct
3 Correct 27 ms 4976 KB Output is correct
4 Correct 25 ms 4872 KB Output is correct
5 Correct 28 ms 4844 KB Output is correct
6 Correct 23 ms 4808 KB Output is correct
7 Correct 23 ms 4820 KB Output is correct
8 Correct 23 ms 4868 KB Output is correct
9 Correct 22 ms 4788 KB Output is correct
10 Correct 25 ms 4924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4820 KB Output is correct
2 Correct 16 ms 4948 KB Output is correct
3 Correct 15 ms 4812 KB Output is correct
4 Correct 15 ms 4944 KB Output is correct
5 Correct 24 ms 7672 KB Output is correct
6 Correct 16 ms 5972 KB Output is correct
7 Correct 16 ms 6092 KB Output is correct
8 Correct 25 ms 7756 KB Output is correct
9 Correct 24 ms 7628 KB Output is correct
10 Correct 16 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4852 KB Output is correct
2 Correct 27 ms 7860 KB Output is correct
3 Correct 27 ms 7868 KB Output is correct
4 Correct 27 ms 7884 KB Output is correct
5 Correct 27 ms 7940 KB Output is correct
6 Correct 28 ms 7960 KB Output is correct
7 Correct 29 ms 8024 KB Output is correct
8 Correct 34 ms 7864 KB Output is correct
9 Correct 27 ms 8056 KB Output is correct
10 Correct 28 ms 8036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 468 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 0 ms 468 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 1 ms 576 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 468 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 0 ms 468 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 1 ms 576 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 3 ms 3412 KB Output is correct
22 Correct 14 ms 26900 KB Output is correct
23 Correct 3 ms 6356 KB Output is correct
24 Correct 2 ms 3668 KB Output is correct
25 Correct 3 ms 4928 KB Output is correct
26 Correct 2 ms 3120 KB Output is correct
27 Correct 3 ms 4692 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4816 KB Output is correct
2 Correct 27 ms 4908 KB Output is correct
3 Correct 27 ms 4976 KB Output is correct
4 Correct 25 ms 4872 KB Output is correct
5 Correct 28 ms 4844 KB Output is correct
6 Correct 23 ms 4808 KB Output is correct
7 Correct 23 ms 4820 KB Output is correct
8 Correct 23 ms 4868 KB Output is correct
9 Correct 22 ms 4788 KB Output is correct
10 Correct 25 ms 4924 KB Output is correct
11 Correct 15 ms 4820 KB Output is correct
12 Correct 16 ms 4948 KB Output is correct
13 Correct 15 ms 4812 KB Output is correct
14 Correct 15 ms 4944 KB Output is correct
15 Correct 24 ms 7672 KB Output is correct
16 Correct 16 ms 5972 KB Output is correct
17 Correct 16 ms 6092 KB Output is correct
18 Correct 25 ms 7756 KB Output is correct
19 Correct 24 ms 7628 KB Output is correct
20 Correct 16 ms 6100 KB Output is correct
21 Correct 25 ms 4852 KB Output is correct
22 Correct 27 ms 7860 KB Output is correct
23 Correct 27 ms 7868 KB Output is correct
24 Correct 27 ms 7884 KB Output is correct
25 Correct 27 ms 7940 KB Output is correct
26 Correct 28 ms 7960 KB Output is correct
27 Correct 29 ms 8024 KB Output is correct
28 Correct 34 ms 7864 KB Output is correct
29 Correct 27 ms 8056 KB Output is correct
30 Correct 28 ms 8036 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 724 KB Output is correct
43 Correct 0 ms 468 KB Output is correct
44 Correct 0 ms 596 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 0 ms 468 KB Output is correct
47 Correct 1 ms 576 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 3 ms 3412 KB Output is correct
52 Correct 14 ms 26900 KB Output is correct
53 Correct 3 ms 6356 KB Output is correct
54 Correct 2 ms 3668 KB Output is correct
55 Correct 3 ms 4928 KB Output is correct
56 Correct 2 ms 3120 KB Output is correct
57 Correct 3 ms 4692 KB Output is correct
58 Correct 1 ms 852 KB Output is correct
59 Correct 1 ms 724 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Execution timed out 1072 ms 34460 KB Time limit exceeded
62 Halted 0 ms 0 KB -