// turmak-_-
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define sz(a) a.size()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ppb pop_back()
#define ll long long
#define ull unsigned long long
#define ld long double
#define IOS ios_base :: sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define X first
#define Y second
using namespace std;
const int N = (int)1e5 + 7 ;
const ll MOD = (ll)998244353;
const ll INF = (ll)1e18 + 7;
const int inf = (int)1e9 + 7;
pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int a[N],n,k;
int mn = inf;
void go(int mx, int num, int id, int sum) {
if(id==n+1 && num!=0) {
return;
}
if(id==n+1 && num==0) {
mn = min(mn, sum);
}
if(id==n+1) return;
go(a[id], num-1, id+1, sum+a[id]);
go(max(mx,a[id]), num, id+1, sum-mx+max(mx,a[id]));
}
void solve() {
cin>>n>>k;
for(int i=1; i<=n; ++i) cin>>a[i];
go(0,k,1,0);
cout<<mn<<nl;
}
int main() {
IOS
//freopen("cinema.in", "r", stdin);
//freopen("cinema.out", "w", stdout);
int tt=1;
// cin>>tt;
while(tt--) {
solve();
}
IOI
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
388 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Execution timed out |
1079 ms |
364 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 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 |
8 ms |
364 KB |
Output is correct |
15 |
Correct |
9 ms |
364 KB |
Output is correct |
16 |
Correct |
7 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
364 KB |
Output is correct |
18 |
Correct |
8 ms |
364 KB |
Output is correct |
19 |
Correct |
9 ms |
364 KB |
Output is correct |
20 |
Correct |
10 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
388 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Execution timed out |
1079 ms |
364 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
388 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Execution timed out |
1079 ms |
364 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |