#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>
using ll = long long;
using namespace std;
constexpr int nm = 5002;
int n;
pair<ll, ll> a[nm];
ll dp[nm][nm];
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
return a.first + a.second < b.first + b.second;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].second;
for (int i = 1; i <= n; ++i) cin >> a[i].first;
sort(a + 1, a + n + 1, cmp);
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
dp[i][0] = 0;
for (int j = 1; j <= i; ++j) {
dp[i][j] = dp[i - 1][j];
if (dp[i - 1][j - 1] <= a[i].first) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].second);
}
}
}
for (int i = n; i >= 0; --i) {
if (dp[n][i] < 1e18) {
cout << i << "\n";
return 0;
}
}
}
| # | 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... |