Untitled
unknown
plain_text
a year ago
1.8 kB
9
Indexable
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define el <<'\n' ;
#define ll long long
#define Lol ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(n) (int)n.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,num) memset(arr, num, sizeof(arr))
int dx[]= { -1,1,0,0 } ;
int dy[]= { 0,0,-1,1 } ;
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree< int , null_type,greater< int >, rb_tree_tag,tree_order_statistics_node_update>
int dp[2][501][501] ;
void _3K_W_RABK_YFK(){
int k , n , x , y,m ; cin>>k>>x>>y>>n>>m ;
vector<pair<int,int>>v(k) ;
for( int i=0 ;i<k ; ++i ) cin>>v[i].first ;
for( int i=0 ;i<k ; ++i ) cin>>v[i].second ;
int p=0 ;
for( int i=k-1; i>=0 ; --i ){
for( int j=0 ; j<=x ; ++j ){
for( int o=0 ; o<=y ; ++o ){
dp[p][j][o]=dp[!p][j][o] ;
if( o-v[i].first-m >=0 ){
dp[p][j][o]=max( dp[p][j][o] , v[i].second+dp[!p][j][o-v[i].first-m] ) ;
}
if( j-v[i].first-n >=0 ){
dp[p][j][o]=max( dp[p][j][o] , v[i].second+dp[!p][j-v[i].first-n][o] ) ;
}
}
}
p=!p ;
}
int ans=0 ;
for( int i=0 ; i<=x; ++i ){
for( int j=0 ; j<=y ; ++j )
ans=max(ans,dp[0][i][j]) ,ans=max(ans,dp[1][i][j]) ;
}
cout<<ans el
}
int32_t main()
{
Lol
//freopen("alone.in", "r", stdin);
//freopen("closing.out", "w", stdout);
int t=1 ;// cin>>t ;
for( int i=1; i<=t; ++i ){
_3K_W_RABK_YFK();
}
return 0 ;
}
/* practice makes PERFECT */Editor is loading...
Leave a Comment