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;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i -= (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
typedef long long ll;
const int INF = (int)1e9;
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int n = a.size();
multiset<int> se;
vector<vector<int>> f(n + 1, vector<int>(y + 1, 0));
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), [&](int lhs, int rhs){
return a[lhs] < a[rhs];
});
REPD(i, n - 1){
se.insert(b[sorted[i]]);
int curr = 0;
for(int tm : se){
curr += tm;
if(curr <= y)
f[i][curr]++;
else
break;
}
FOR(j, 1, y + 1, 1){
f[i][j] += f[i][j - 1];
}
}
int ans = 0;
vector<int> dp(x + 1, y);
vector<int> new_dp(x + 1);
REP(i, n){
fill(new_dp.begin(), new_dp.end(), -INF);
REP(j, x + 1){
new_dp[j] = dp[j] - b[sorted[i]];
if(j - a[sorted[i]] >= 0){
new_dp[j - a[sorted[i]]] = max(new_dp[j - a[sorted[i]]], dp[j]);
}
}
dp.swap(new_dp);
REP(j, x + 1){
if(dp[j] >= 0){
ans = max(ans, i + 1 + f[i + 1][dp[j]]);
}
}
}
ans = max(ans, f[0][y]);
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... |