이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Dedicated to my love, ivaziva
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define here cerr<<"---------------------------------\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
#define ll long long
#define ld long double
#define llinf 100000000000000000LL
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define sz(s) (ll)(s.size())
#define ios ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
#define mod 1000000007
using namespace std;
/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
ll add(ll x,ll y){
if(x+y>=mod) return x+y-mod;
return x+y;
}
ll sub(ll x,ll y){
if(x-y<0) return x-y+mod;
return x-y;
}
ll mul(ll x,ll y){
ll res=(x*y)%mod;
if(res<0) res+=mod;
return res;
}
ll pw(ll x,ll y){
ll ret=1,bs=x;
for(;y;y>>=1){
if(y&1) ret=mul(ret,bs);
bs=mul(bs,bs);
}
return ret%mod;
}*/
#define maxn 2005
ll n,s;
ll v[maxn],w[maxn];
vector<pll> c[maxn];
void tc(){
cin >> s >> n;
for(ll i = 1;i<=n;i++){
ll vu,wu,k;
cin >> vu >> wu >> k;
c[wu].pb({vu,k});
}
ll id=1;
for(ll i = 1;i<=s;i++){
if(sz(c[i])==0) continue;
sort(c[i].rbegin(),c[i].rend());
ll mx=s/i;
for(ll j = 0;j<sz(c[i]);j++){
ll cnt=1;
for(;cnt<=min(c[i][j].sc,mx);cnt++){
v[id]=c[i][j].fi;
w[id]=i;
id++;
}
}
}
--id;
n=id;
ll dp[n+1][s+1][2];
for(ll i = 1;i<=n;i++){
for(ll j = 0;j<=s;j++) dp[i][j][0]=0,dp[i][j][1]=0;
}
dp[1][0][0]=0;
dp[1][w[1]][1]=v[1];
for(ll i = 2;i<=n;i++){
for(ll j = 0;j<=s;j++){
dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1]);
if(j+w[i]<=s){
dp[i][j+w[i]][1]=max(dp[i][j+w[i]][1],dp[i-1][j][0]+v[i]);
dp[i][j+w[i]][1]=max(dp[i][j+w[i]][1],dp[i-1][j][1]+v[i]);
}
}
}
ll ans=0;
for(ll i = 0;i<=s;i++){
ans=max(ans,max(dp[n][i][0],dp[n][i][1]));
// cerr<<"dp[n][i]: "<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl;
}
cout<<ans<<endl;
}
int main(){
ios
int t; t = 1;
// cin >> t;
while(t--){
tc();
}
return 0;
}
# | 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... |