#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=6005;
int dp[N][N],n,k,a[N],b[N];
bool vis[N][N];
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Partially correct |
0 ms |
2396 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
4 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
5 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
6 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
7 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
8 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
9 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
10 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
11 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
4 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
5 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
6 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
7 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
8 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
9 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
10 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
11 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
12 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
13 |
Partially correct |
0 ms |
2396 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
15 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
16 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
17 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
18 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
19 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
20 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
21 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
22 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
23 |
Partially correct |
459 ms |
200532 KB |
Partially correct |
24 |
Partially correct |
20 ms |
90456 KB |
Partially correct |
25 |
Partially correct |
159 ms |
131556 KB |
Partially correct |
26 |
Partially correct |
34 ms |
96816 KB |
Partially correct |
27 |
Partially correct |
331 ms |
175956 KB |
Partially correct |
28 |
Partially correct |
25 ms |
94300 KB |
Partially correct |
29 |
Partially correct |
373 ms |
186880 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
2 |
Partially correct |
0 ms |
2396 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
4 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
5 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
6 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
7 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
8 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
9 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
10 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
11 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
12 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
13 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
15 |
Partially correct |
0 ms |
2396 KB |
Partially correct |
16 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
17 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
18 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
19 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
20 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
21 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
22 |
Partially correct |
1 ms |
11356 KB |
Partially correct |
23 |
Partially correct |
2 ms |
11352 KB |
Partially correct |
24 |
Partially correct |
2 ms |
11356 KB |
Partially correct |
25 |
Partially correct |
459 ms |
200532 KB |
Partially correct |
26 |
Partially correct |
20 ms |
90456 KB |
Partially correct |
27 |
Partially correct |
159 ms |
131556 KB |
Partially correct |
28 |
Partially correct |
34 ms |
96816 KB |
Partially correct |
29 |
Partially correct |
331 ms |
175956 KB |
Partially correct |
30 |
Partially correct |
25 ms |
94300 KB |
Partially correct |
31 |
Partially correct |
373 ms |
186880 KB |
Partially correct |
32 |
Partially correct |
1 ms |
2396 KB |
Partially correct |
33 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |