元のタイトル
コードの実装(ほとんどの自己解決型の最初のブラシ)
void sort(int* scores,int* ages,int scoresSize)
{
int i,j,temp1,temp2;
for(i=0;i<scoresSize-1;i++)
{
for(j=i+1;j<scoresSize;j++)
{
if(ages[i] > ages[j] || (ages[i] == ages[j] && scores[i] > scores[j]))
{
temp1 = ages[i];
ages[i] = ages[j];
ages[j] = temp1;
temp2 = scores[i];
scores[i] = scores[j];
scores[j] = temp2;
}
}
}
}
int bestTeamScore(int* scores, int scoresSize, int* ages, int agesSize){
sort(scores,ages,scoresSize);
int* dp = (int*)malloc(sizeof(int) * (agesSize+1)),i,j,max = scores[0];
memset(dp,0,sizeof(int) * (agesSize+1));
dp[0] = scores[0];
for(i=1;i<scoresSize;i++)
{
dp[i] = scores[i];
for(j=0;j<i;j++)
{
if(ages[i] == ages[j] || scores[i] >= scores[j])
dp[i] = fmax(dp[i],scores[i]+dp[j]);
}
if(dp[i] > max) max = dp[i];
}
return max;
}