Submission #886948

# Submission time Handle Problem Language Result Execution time Memory
886948 2023-12-13T08:43:32 Z alexdd K blocks (IZhO14_blocks) C++17
100 / 100
144 ms 126984 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n,k;
int a[100005];
deque<pair<int,int>> dq[100005];
int dp[100005];
signed main()
{
    cin>>n>>k;
    for(int i=0;i<=k;i++)
        dp[i]=-INF;
    int minpref=INF;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i] = 1000000000 - a[i];
        minpref = min(minpref, a[i]);
        for(int j=k;j>1;j--)
        {
            int mxm=-INF;
            while(!dq[j].empty() && a[i]<=dq[j].back().second)
            {
                mxm = max(mxm, dq[j].back().first - dq[j].back().second);
                dq[j].pop_back();
            }
            mxm = max(mxm, dp[j-1]);
            if(mxm!=-INF && (dq[j].empty() || mxm+a[i] > dq[j].back().first)) dq[j].push_back({mxm+a[i],a[i]});
            if(!dq[j].empty()) dp[j] = dq[j].back().first;
            else dp[j]=-INF;
        }
        dp[1] = minpref;
    }
    cout<<1000000000 * k - dp[k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 68188 KB Output is correct
2 Correct 30 ms 68236 KB Output is correct
3 Correct 29 ms 68176 KB Output is correct
4 Correct 30 ms 68184 KB Output is correct
5 Correct 31 ms 68264 KB Output is correct
6 Correct 30 ms 68176 KB Output is correct
7 Correct 30 ms 68188 KB Output is correct
8 Correct 30 ms 68184 KB Output is correct
9 Correct 29 ms 68156 KB Output is correct
10 Correct 30 ms 68184 KB Output is correct
11 Correct 30 ms 68216 KB Output is correct
12 Correct 34 ms 68236 KB Output is correct
13 Correct 30 ms 68188 KB Output is correct
14 Correct 32 ms 68184 KB Output is correct
15 Correct 31 ms 68176 KB Output is correct
16 Correct 31 ms 68220 KB Output is correct
17 Correct 30 ms 68220 KB Output is correct
18 Correct 30 ms 68188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 68188 KB Output is correct
2 Correct 30 ms 68176 KB Output is correct
3 Correct 30 ms 68188 KB Output is correct
4 Correct 34 ms 68188 KB Output is correct
5 Correct 31 ms 68192 KB Output is correct
6 Correct 33 ms 68292 KB Output is correct
7 Correct 35 ms 68180 KB Output is correct
8 Correct 30 ms 68240 KB Output is correct
9 Correct 31 ms 68188 KB Output is correct
10 Correct 37 ms 68432 KB Output is correct
11 Correct 30 ms 68188 KB Output is correct
12 Correct 30 ms 68188 KB Output is correct
13 Correct 30 ms 68184 KB Output is correct
14 Correct 31 ms 68296 KB Output is correct
15 Correct 30 ms 68352 KB Output is correct
16 Correct 30 ms 68188 KB Output is correct
17 Correct 30 ms 68180 KB Output is correct
18 Correct 30 ms 68188 KB Output is correct
19 Correct 32 ms 68444 KB Output is correct
20 Correct 30 ms 68184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 68188 KB Output is correct
2 Correct 30 ms 68236 KB Output is correct
3 Correct 29 ms 68176 KB Output is correct
4 Correct 30 ms 68184 KB Output is correct
5 Correct 31 ms 68264 KB Output is correct
6 Correct 30 ms 68176 KB Output is correct
7 Correct 30 ms 68188 KB Output is correct
8 Correct 30 ms 68184 KB Output is correct
9 Correct 29 ms 68156 KB Output is correct
10 Correct 30 ms 68184 KB Output is correct
11 Correct 30 ms 68216 KB Output is correct
12 Correct 34 ms 68236 KB Output is correct
13 Correct 30 ms 68188 KB Output is correct
14 Correct 32 ms 68184 KB Output is correct
15 Correct 31 ms 68176 KB Output is correct
16 Correct 31 ms 68220 KB Output is correct
17 Correct 30 ms 68220 KB Output is correct
18 Correct 30 ms 68188 KB Output is correct
19 Correct 30 ms 68188 KB Output is correct
20 Correct 30 ms 68176 KB Output is correct
21 Correct 30 ms 68188 KB Output is correct
22 Correct 34 ms 68188 KB Output is correct
23 Correct 31 ms 68192 KB Output is correct
24 Correct 33 ms 68292 KB Output is correct
25 Correct 35 ms 68180 KB Output is correct
26 Correct 30 ms 68240 KB Output is correct
27 Correct 31 ms 68188 KB Output is correct
28 Correct 37 ms 68432 KB Output is correct
29 Correct 30 ms 68188 KB Output is correct
30 Correct 30 ms 68188 KB Output is correct
31 Correct 30 ms 68184 KB Output is correct
32 Correct 31 ms 68296 KB Output is correct
33 Correct 30 ms 68352 KB Output is correct
34 Correct 30 ms 68188 KB Output is correct
35 Correct 30 ms 68180 KB Output is correct
36 Correct 30 ms 68188 KB Output is correct
37 Correct 32 ms 68444 KB Output is correct
38 Correct 30 ms 68184 KB Output is correct
39 Correct 30 ms 68180 KB Output is correct
40 Correct 29 ms 68188 KB Output is correct
41 Correct 30 ms 68368 KB Output is correct
42 Correct 31 ms 68244 KB Output is correct
43 Correct 30 ms 68188 KB Output is correct
44 Correct 31 ms 68220 KB Output is correct
45 Correct 30 ms 68188 KB Output is correct
46 Correct 35 ms 68316 KB Output is correct
47 Correct 31 ms 68188 KB Output is correct
48 Correct 30 ms 68348 KB Output is correct
49 Correct 30 ms 68236 KB Output is correct
50 Correct 33 ms 68180 KB Output is correct
51 Correct 30 ms 68188 KB Output is correct
52 Correct 30 ms 68188 KB Output is correct
53 Correct 34 ms 68176 KB Output is correct
54 Correct 30 ms 68188 KB Output is correct
55 Correct 31 ms 68304 KB Output is correct
56 Correct 30 ms 68188 KB Output is correct
57 Correct 31 ms 68180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 68188 KB Output is correct
2 Correct 30 ms 68236 KB Output is correct
3 Correct 29 ms 68176 KB Output is correct
4 Correct 30 ms 68184 KB Output is correct
5 Correct 31 ms 68264 KB Output is correct
6 Correct 30 ms 68176 KB Output is correct
7 Correct 30 ms 68188 KB Output is correct
8 Correct 30 ms 68184 KB Output is correct
9 Correct 29 ms 68156 KB Output is correct
10 Correct 30 ms 68184 KB Output is correct
11 Correct 30 ms 68216 KB Output is correct
12 Correct 34 ms 68236 KB Output is correct
13 Correct 30 ms 68188 KB Output is correct
14 Correct 32 ms 68184 KB Output is correct
15 Correct 31 ms 68176 KB Output is correct
16 Correct 31 ms 68220 KB Output is correct
17 Correct 30 ms 68220 KB Output is correct
18 Correct 30 ms 68188 KB Output is correct
19 Correct 30 ms 68188 KB Output is correct
20 Correct 30 ms 68176 KB Output is correct
21 Correct 30 ms 68188 KB Output is correct
22 Correct 34 ms 68188 KB Output is correct
23 Correct 31 ms 68192 KB Output is correct
24 Correct 33 ms 68292 KB Output is correct
25 Correct 35 ms 68180 KB Output is correct
26 Correct 30 ms 68240 KB Output is correct
27 Correct 31 ms 68188 KB Output is correct
28 Correct 37 ms 68432 KB Output is correct
29 Correct 30 ms 68188 KB Output is correct
30 Correct 30 ms 68188 KB Output is correct
31 Correct 30 ms 68184 KB Output is correct
32 Correct 31 ms 68296 KB Output is correct
33 Correct 30 ms 68352 KB Output is correct
34 Correct 30 ms 68188 KB Output is correct
35 Correct 30 ms 68180 KB Output is correct
36 Correct 30 ms 68188 KB Output is correct
37 Correct 32 ms 68444 KB Output is correct
38 Correct 30 ms 68184 KB Output is correct
39 Correct 30 ms 68180 KB Output is correct
40 Correct 29 ms 68188 KB Output is correct
41 Correct 30 ms 68368 KB Output is correct
42 Correct 31 ms 68244 KB Output is correct
43 Correct 30 ms 68188 KB Output is correct
44 Correct 31 ms 68220 KB Output is correct
45 Correct 30 ms 68188 KB Output is correct
46 Correct 35 ms 68316 KB Output is correct
47 Correct 31 ms 68188 KB Output is correct
48 Correct 30 ms 68348 KB Output is correct
49 Correct 30 ms 68236 KB Output is correct
50 Correct 33 ms 68180 KB Output is correct
51 Correct 30 ms 68188 KB Output is correct
52 Correct 30 ms 68188 KB Output is correct
53 Correct 34 ms 68176 KB Output is correct
54 Correct 30 ms 68188 KB Output is correct
55 Correct 31 ms 68304 KB Output is correct
56 Correct 30 ms 68188 KB Output is correct
57 Correct 31 ms 68180 KB Output is correct
58 Correct 33 ms 68432 KB Output is correct
59 Correct 39 ms 68952 KB Output is correct
60 Correct 42 ms 68952 KB Output is correct
61 Correct 50 ms 68944 KB Output is correct
62 Correct 80 ms 69772 KB Output is correct
63 Correct 54 ms 69620 KB Output is correct
64 Correct 65 ms 69712 KB Output is correct
65 Correct 31 ms 68188 KB Output is correct
66 Correct 32 ms 68440 KB Output is correct
67 Correct 30 ms 68188 KB Output is correct
68 Correct 30 ms 68348 KB Output is correct
69 Correct 30 ms 68172 KB Output is correct
70 Correct 31 ms 68184 KB Output is correct
71 Correct 36 ms 68444 KB Output is correct
72 Correct 32 ms 68444 KB Output is correct
73 Correct 33 ms 68436 KB Output is correct
74 Correct 40 ms 68956 KB Output is correct
75 Correct 41 ms 68956 KB Output is correct
76 Correct 54 ms 68948 KB Output is correct
77 Correct 84 ms 69760 KB Output is correct
78 Correct 53 ms 69656 KB Output is correct
79 Correct 68 ms 69716 KB Output is correct
80 Correct 60 ms 69976 KB Output is correct
81 Correct 58 ms 69632 KB Output is correct
82 Correct 89 ms 69712 KB Output is correct
83 Correct 30 ms 68184 KB Output is correct
84 Correct 31 ms 68188 KB Output is correct
85 Correct 44 ms 74068 KB Output is correct
86 Correct 35 ms 68684 KB Output is correct
87 Correct 37 ms 69716 KB Output is correct
88 Correct 39 ms 68944 KB Output is correct
89 Correct 46 ms 70228 KB Output is correct
90 Correct 72 ms 88420 KB Output is correct
91 Correct 144 ms 126984 KB Output is correct
92 Correct 57 ms 70736 KB Output is correct
93 Correct 92 ms 94800 KB Output is correct
94 Correct 34 ms 68444 KB Output is correct
95 Correct 35 ms 68436 KB Output is correct
96 Correct 32 ms 68184 KB Output is correct
97 Correct 30 ms 68180 KB Output is correct
98 Correct 30 ms 68180 KB Output is correct
99 Correct 31 ms 68188 KB Output is correct