#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ppii pair<pii, pii>
#define tiii tuple<int, int, int>
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define f first
#define s second
#define pb push_back
const int N = 5005;
const int MOD = 1e9+7;
int ans[N][N];
bool comp(pii p, pii q) {
return (p.f+p.s < q.f+q.s);
}
signed main() {
// freopen("in.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<pii> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].s;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) ans[i][j] = LLONG_MAX;
}
for (int i = 0; i < n; i++) cin >> a[i].f;
sort(a.begin(), a.end(), comp);
ans[0][0] = 0;
ans[0][1] = a[0].s;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i+1; j++) {
ans[i][j] = ans[i-1][j];
if (a[i].f < ans[i-1][j-1]) continue;
ans[i][j] = min(ans[i][j], ans[i-1][j-1]+a[i].s);
}
}
for (int i = 1; i <= n; i++) {
if (ans[n-1][i] == LLONG_MAX) {
cout << i-1;
exit(0);
}
}
cout << n;
}
| # | 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... |