| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 561030 | hoanghq2004 | Jelly Flavours (IOI20_jelly) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
