#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=3e5+5,K=205;
int dp[N][K],n,k,a[N],b[N];
bool vis[N][K];
int rec(int i,int j){
if (j==k) return 0;
if (j>k) return -1e15;
if (i>n) return -1e15;
if (vis[i][j]) return dp[i][j];
vis[i][j]=1;
if (j==0) return dp[i][j]=max(rec(i+1,j),rec(i+1,j+1)+b[i]-a[i]);
return dp[i][j]=max(rec(i+1,j)-a[i],rec(i+1,j+1)+b[i]-a[i]);
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) cin>>b[i];
cout<<rec(1,0)<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
2 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
2 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
3 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
4 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
5 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
6 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
7 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
8 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
9 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
10 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
11 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
2 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
3 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
4 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
5 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
6 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
7 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
8 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
9 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
10 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
11 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
12 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
13 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
14 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
15 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
16 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
17 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
18 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
19 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
20 |
Partially correct |
1 ms |
6668 KB |
Partially correct |
21 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
22 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
23 |
Incorrect |
12 ms |
18464 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
2 |
Partially correct |
168 ms |
475220 KB |
Partially correct |
3 |
Partially correct |
179 ms |
477520 KB |
Partially correct |
4 |
Partially correct |
210 ms |
477472 KB |
Partially correct |
5 |
Partially correct |
170 ms |
477528 KB |
Partially correct |
6 |
Partially correct |
175 ms |
477116 KB |
Partially correct |
7 |
Partially correct |
165 ms |
476608 KB |
Partially correct |
8 |
Partially correct |
173 ms |
477524 KB |
Partially correct |
9 |
Partially correct |
171 ms |
476048 KB |
Partially correct |
10 |
Partially correct |
186 ms |
476496 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
2 |
Partially correct |
168 ms |
475220 KB |
Partially correct |
3 |
Partially correct |
179 ms |
477520 KB |
Partially correct |
4 |
Partially correct |
210 ms |
477472 KB |
Partially correct |
5 |
Partially correct |
170 ms |
477528 KB |
Partially correct |
6 |
Partially correct |
175 ms |
477116 KB |
Partially correct |
7 |
Partially correct |
165 ms |
476608 KB |
Partially correct |
8 |
Partially correct |
173 ms |
477524 KB |
Partially correct |
9 |
Partially correct |
171 ms |
476048 KB |
Partially correct |
10 |
Partially correct |
186 ms |
476496 KB |
Partially correct |
11 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
12 |
Partially correct |
161 ms |
475508 KB |
Partially correct |
13 |
Partially correct |
181 ms |
477484 KB |
Partially correct |
14 |
Partially correct |
170 ms |
477552 KB |
Partially correct |
15 |
Partially correct |
184 ms |
477632 KB |
Partially correct |
16 |
Partially correct |
183 ms |
477008 KB |
Partially correct |
17 |
Partially correct |
182 ms |
476756 KB |
Partially correct |
18 |
Partially correct |
185 ms |
477520 KB |
Partially correct |
19 |
Partially correct |
166 ms |
475988 KB |
Partially correct |
20 |
Partially correct |
168 ms |
476664 KB |
Partially correct |
21 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
22 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
23 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
24 |
Partially correct |
1 ms |
6624 KB |
Partially correct |
25 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
26 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
27 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
28 |
Partially correct |
1 ms |
6608 KB |
Partially correct |
29 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
30 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
31 |
Partially correct |
1841 ms |
477688 KB |
Partially correct |
32 |
Partially correct |
220 ms |
477520 KB |
Partially correct |
33 |
Partially correct |
1847 ms |
477200 KB |
Partially correct |
34 |
Partially correct |
1816 ms |
476992 KB |
Partially correct |
35 |
Partially correct |
1976 ms |
476852 KB |
Partially correct |
36 |
Partially correct |
1980 ms |
476012 KB |
Partially correct |
37 |
Partially correct |
2079 ms |
475476 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
2 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
3 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
4 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
5 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
6 |
Partially correct |
1 ms |
6488 KB |
Partially correct |
7 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
8 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
9 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
10 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
11 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
12 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
13 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
14 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
15 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
16 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
17 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
18 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
19 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
20 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
21 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
22 |
Partially correct |
1 ms |
6668 KB |
Partially correct |
23 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
24 |
Partially correct |
1 ms |
6492 KB |
Partially correct |
25 |
Incorrect |
12 ms |
18464 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |