#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vect;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pb push_back
#define f first
#define s second
int find_maximum_unique(int x, int y, vect a, vect b){
int n = a.size();
vector<pair<pii, int>> v;
v.pb({{0, 0}, 0});
for(int i = 0; i < n; i++){
v.pb({{a[i], b[i]}, i + 1});
}
sort(v.begin(), v.end());
vector<vect> dp(n + 1, vect(x + 1, 1e9));
for(int i = 0; i <= x; i++){
dp[0][i] = 0;
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= x; j++){
dp[i][j] = dp[i - 1][j] + v[i].f.s;
if(j >= v[i].f.f) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i].f.f]);
}
}
set<pii> s;
for(int i = 1; i <= n; i++){
s.insert({v[i].s, i});
}
int wyn = 0;
for(int i = 0; i <= n; i++){
int best = 1e9;
for(int j = 0; j <= x; j++){
best = min(dp[i][j], best);
}
if(best > y) continue;
y -= best;
int ile = 0;
for(pii a : s){
int val = a.f;
if(val > y) break;
y -= val;
ile++;
break;
}
if(i != n){
s.erase({v[i + 1].f.s, i + 1});
}
wyn = max(wyn, ile + i);
}
return wyn;
}
| # | 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... |