#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vi vector<long long>
#define all(x) x.begin(), x.end()
#define endl "\n"
void solution();
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solution();
return 0;
}
const int N = 5e3+10;
ll dp[N][N];
ll l[N], x[N];
void solution() {
ll n; cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> l[i];
for (int i = 0; i <= n; i++) {
fill(dp[i], dp[i]+n+1, 1e18);
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] = min(dp[i][j], dp[i-1][j]);
if (j > 0 && l[i] >= dp[i-1][j-1]) {
dp[i][j] = min(dp[i][j], dp[i-1][j-1] + x[i]);
}
}
}
for (int j = n; j >= 0; j--) {
if (dp[n][j] != 1e18) {
cout << j << endl;
return;
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |