#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12;
const ll INF=1e15+7;
int q[N],n;
bool vis[N][101];
ll dp[N][101];
ll rec(int i,int k,ll sum){
if (i == n && k == 0)ret sum;
if (k == 0 || k != 0 && i == n)ret INF;
int mx=0,j;
ll ans=INF;
for (j=i+1;j<=n;++j){
mx = max(mx,q[j]);
ans = min(ans,rec(j,k-1,sum+mx));
}
ret dp[i][k] = ans;
}
main(){
int i,k;
scan2(n,k)
for (i=1;i<=n;++i){
scan1(q[i])
}
cout <<rec(0,k,0);
}
Compilation message
blocks.cpp: In function 'long long int rec(int, int, long long int)':
blocks.cpp:31:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
31 | if (k == 0 || k != 0 && i == n)ret INF;
| ~~~~~~~^~~~~~~~~
blocks.cpp: At global scope:
blocks.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main(){
| ^
blocks.cpp: In function 'int main()':
blocks.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
15 | #define scan2(a,b) scanf("%d %d",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:43:5: note: in expansion of macro 'scan2'
43 | scan2(n,k)
| ^~~~~
blocks.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
14 | #define scan1(a) scanf("%d",&a);
| ~~~~~^~~~~~~~~
blocks.cpp:45:9: note: in expansion of macro 'scan1'
45 | scan1(q[i])
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
505 ms |
492 KB |
Output is correct |
14 |
Correct |
501 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
506 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
6 ms |
364 KB |
Output is correct |
15 |
Correct |
6 ms |
364 KB |
Output is correct |
16 |
Correct |
9 ms |
364 KB |
Output is correct |
17 |
Correct |
9 ms |
364 KB |
Output is correct |
18 |
Correct |
6 ms |
364 KB |
Output is correct |
19 |
Correct |
9 ms |
364 KB |
Output is correct |
20 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
505 ms |
492 KB |
Output is correct |
14 |
Correct |
501 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
506 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
6 ms |
364 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
9 ms |
364 KB |
Output is correct |
35 |
Correct |
9 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
364 KB |
Output is correct |
38 |
Correct |
9 ms |
364 KB |
Output is correct |
39 |
Execution timed out |
1086 ms |
364 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
505 ms |
492 KB |
Output is correct |
14 |
Correct |
501 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
506 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
6 ms |
364 KB |
Output is correct |
33 |
Correct |
6 ms |
364 KB |
Output is correct |
34 |
Correct |
9 ms |
364 KB |
Output is correct |
35 |
Correct |
9 ms |
364 KB |
Output is correct |
36 |
Correct |
6 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
364 KB |
Output is correct |
38 |
Correct |
9 ms |
364 KB |
Output is correct |
39 |
Execution timed out |
1086 ms |
364 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |