Yuna traveled into the fantasy world. The gods of this world gave her a powerful set of equipment so that she could defeat many fierce monsters. However, she had limited health points and stamina, and she could not kill a large number of monsters.
Adventurer's guild would release n monster crusade missions, such as black python and wild wolf. Completing the i-th mission would consume Yuna hi health points and si stamina, and then she would get wi gold coins.
In the beginning, Yuna had H health points and S stamina. When her health points were dropped to less than or equal to 0, she would die. However, when her stamina was dropped to less than 0, she would not give up, and then the overdrawn stamina would be reduced from health points. For example, her health points would be reduced by 3, when her stamina dropped to −3, and then her stamina would be reset to 0. If her health points can not afford the overdrawn stamina, she would also die.
As a friend of Yuna, can you help her choose some missions to complete to get the maximum number of gold coins? Make sure Yuna does not die, or you will be very sad.
Input
The first line contains three integers n,H,S(1≤n≤1000,1≤H≤300,0≤S≤300).
The next n lines describe all the monster crusade missions, where the i-th line contains three integers hi,si,wi (0≤hi,si≤300,1≤wi≤109).
Output
Print one integer – the maximum number of gold coins that Yuna could get.
Examples
Inputcopy | Outputcopy |
---|---|
2 66 22 1 23 2 66 8 90 | 2 |
Inputcopy | Outputcopy |
---|---|
4 16 22 1 23 11 5 8 14 2 36 99 15 22 27 | 27 |
#include<bits/stdc++.h>
using namespace std;
long long dp[301][301];//j代表h健康 k代表s耐力
int n,H,S;
int h[1001],s[1001],w[1001];
int main()
{
cin>>n>>H>>S;
for(int i=1;i<=n;i++)
{
cin>>h[i]>>s[i]>>w[i];//h健康,s耐力,w金币
}
for(int i=1;i<=n;i++)
{
for(int j=H;j>=0;j--)
{
for(int k=S;k>=0;k--)
{
if(j>h[i]&&k>=s[i])//当生命与耐力都足够时
{
dp[j][k]=max(dp[j][k],dp[j-h[i]][k-s[i]]+w[i]);
}
else//当耐力不够但是生命+耐力足够时,耐力清零
{
if(k<s[i]&&j+k>(h[i]+s[i]))
dp[j][k]=max(dp[j][k],dp[k+j-(h[i]+s[i])][0]+w[i]);
}
}
}
}
cout<<dp[H][S];
return 0;
}