#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;
// #pragma GCC target ("avx2")
// #pragma GCC optimize ("O3")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC optimize("fast-math")
#define ll long long
#define ld long double
#define vi vector<ll>
#define endl "\n"
#define pr pair<ll, ll>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
void _p(ll a){cout<<a<<endl;}
void _p(string a){cout<<a<<endl;}
void _p(ld a) {cout<<a<<endl;}
template <class T>
void _p(vector<T> a){for(T val:a)cout<<val<<" ";cout<<endl;}
#define debug(x) cout<<#x<<" -> ";_p(x)
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
vector<pr> move8 = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
vector<pr> move4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<pr> move2 = {{0, 1}, {1, 0}};
void solution();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solution();
return 0;
}
void solution() {
ll n; cin >> n;
vector<pr> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].ss;
}
for (int i = 0; i < n; i++) {
cin >> a[i].ff;
}
sort(all(a), greater<pr>());
vector<pr> dp(n+1);
for (int i = n-1; i >= 0; i--) {
for (int j = i+1; j <= n; j++) {
if (a[i].ff >= dp[j].ss) {
if (dp[i].ff == dp[j].ff+1) {
dp[i].ss = min(dp[i].ss, dp[j].ss + a[i].ss) ;
} else if (dp[i].ff <= dp[j].ff) {
dp[i] = {dp[j].ff + 1, dp[j].ss + a[i].ss};
}
}
}
}
ll mx = 0;
for (auto [x,y] : dp) mx = max(mx, x);
cout << mx;
}
| # | 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... |