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 "jelly.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
const int MAXN = 2013;
const int MAXV = 10013;
const int INF = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
pii arr[MAXN];
int dp[MAXN][MAXV + 3], dp1[MAXN][MAXV + 3];
int ans;
int find_maximum_unique(int X, int Y, vi A, vi B)
{
N = SZ(A);
FOR(i, 0, N)
{
arr[i] = {A[i], B[i]};
}
sort(arr, arr + N);
// FOR(i, 0, N)
// {
// cerr << arr[i].fi << ',' << arr[i].se << endl;
// }
fill(dp[0], dp[0] + X + 1, INF);
dp[0][0] = 0;
FOR(i, 0, N)
{
fill(dp[i + 1], dp[i + 1] + X + 1, INF);
FOR(j, 0, X + 1)
{
if (j + arr[i].fi <= X)
{
ckmin(dp[i + 1][j + arr[i].fi], dp[i][j]);
}
ckmin(dp[i + 1][j], dp[i][j] + arr[i].se);
}
}
// cerr << "ayee\n";
//so you know you're going to take a prefix of A.
//dp[pos][# money spent in fi] = min cost in se
//how many things can we buy with this much money.
//dp1[pos][# of money left in se] = max things to buy.
FORD(i, N, 0)
{
FORD(j, Y + 1, 0)
{
if (j >= arr[i].se)
{
ckmax(dp1[i][j - arr[i].se], dp1[i + 1][j] + 1);
}
ckmax(dp1[i][j], dp1[i + 1][j]);
}
}
FOR(i, 0, N + 1)
{
FOR(j, 0, X + 1)
{
if (dp[i][j] <= Y)
{
ckmax(ans, i + dp1[i][dp[i][j]]);
}
}
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |