problem
solution
codes
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1010;
int tot, n(1), f[maxn][maxn];
void dp(int root){
int time, pic;
cin>>time>>pic;
time *= 2;
if(!pic){
int lch(++n), rch(++n);
dp(lch);
dp(rch);
for(int i = time; i<= tot; i++)
for(int j = 0; j <= i-time; j++)
f[root][i]=max(f[root][i], f[lch][j]+f[rch][i-time-j]);
}else{
for(int i = time; i <= tot; i++)
f[root][i] = min(pic,(i-time)/5);
}
}
int main(){
cin>>tot;
dp(1);
cout<<f[1][tot]<<"
";
return 0;
}