# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
315902 | TrungNotChung | 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.
//TrungNotChung
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <set>
#define foru(i,a,b) for(int i=a ; i<=b ; ++i)
#define ford(i,a,b) for(int i=b ; i>=a ; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define oo (int)1e9
#define __builtin_popcount __builtin_popcountll
using namespace std;
const int N = 2000;
const int M = 10000;
struct Jelly
{
int a , b;
bool operator < (const Jelly &x)
{
return a < x.a;
}
}f[N];
int dp[N+1][M+1];
int suf[N+1][N+1] , num[N+1][M+1];
int n , w1 , w2;
void solve()
{
cin >> n >> w1 >> w2;
for(int i=1 ; i<=n ; ++i)
{
cin >> f[i].a >> f[i].b;
}
sort(f+1 , f+n+1);
for(int i=1 ; i<=n ; ++i) for(int j=1 ; j<=n ; ++j) suf[i][j] = oo;
for(int i=n ; i>=1 ; --i)
{
for(int j=1 ; j<=(n-i+1) ; ++j)
{
if(i==n)
{
suf[i][j] = f[i].b;
}
else
{
suf[i][j] = min(suf[i+1][j] , suf[i+1][j-1]+f[i].b);
}
if(suf[i][j] <= M) num[i][suf[i][j]] = max(num[i][suf[i][j]] , j);
}
for(int j=1 ; j<=M ; ++j) num[i][j] = max(num[i][j-1] , num[i][j]);
}
int ans = 0;
for(int i=1 ; i<=n ; ++i)
{
for(int j=0 ; j<=w1 ; ++j)
{
dp[i][j] = dp[i-1][j]+f[i].b;
if(j>=f[i].a) dp[i][j] = min(dp[i-1][j-f[i].a] , dp[i][j]);
if(dp[i][j] <= w2)
{
ans = max(ans , i+num[i+1][w2-dp[i][j]]);
}
}
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("JELLY.INP" , "r" , stdin);
//freopen("JELLY.OUT" , "w" , stdout);
solve();
return 0;
}