# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1279170 | ducdev | Gym Badges (NOI22_gymbadges) | C++17 | 962 ms | 204432 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int n, sz;
pair<int, int> a[MAX_N + 5];
namespace SUBTASK_3 {
const int N = 5000;
ll dp[N + 5][N + 5];
void Solve() {
sort(a + 1, a + n + 1);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = 1e18;
};
};
dp[0][0] = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (dp[i][j] <= a[i + 1].first) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + a[i + 1].second);
};
};
for (int i = n; i >= 0; i--) {
if (dp[n][i] != 1e18) {
cout << i << '\n';
break;
};
};
};
}; // namespace SUBTASK_3
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].second;
for (int i = 1; i <= n; i++) cin >> a[i].first;
SUBTASK_3::Solve();
};
Compilation message (stderr)
# | 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... |