# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
561030 | hoanghq2004 | Jelly Flavours (IOI20_jelly) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
pair <int, int> a[2010];
int dp[2010][100010];
int res;
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> x >> y;
for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= x; ++j) {
dp[i][j] = dp[i - 1][j] + a[i].second;
if (j >= a[i].first) dp[i][j] = min(dp[i][j], dp[i - 1][j - a[i].first]);
}
}
for (int i = n; i >= 0; --i) {
int mincost = 1e9, cnt = i;
for (int j = 0; j <= x; ++j)
mincost = min(mincost, dp[i][j]);
if (mincost > y) continue;
vector <int> s;
for (int j = i + 1; j <= n; ++j) s.push_back(a[j].second);
sort(s.begin(), s.end());
for (auto cost: s) {
if (mincost + cost <= y) {
mincost += cost;
++cnt;
}
else break;
}
res = max(res, cnt);
}
cout << res << "\n";
}