function solution(target) {
let dp = Array.from({ length: target + 1 }, () => [Infinity, 0]);
dp[0] = [0, 0];
for (let score = 1; score <= target; score++) {
for (let s = 1; s <= 20; s++) {
for (let hit of [1, 2, 3]) {
let prevScore = score - s * hit;
if (prevScore >= 0) {
let [thrw, singBulls] = dp[prevScore];
if (hit === 1) singBulls++;
if (thrw + 1 < dp[score][0] || (
thrw + 1 === dp[score][0] && singBulls > dp[score][1])) {
dp[score] = [thrw + 1, singBulls];
}
}
}
}
if (score >= 50 && dp[score-50][0] + 1 <= dp[score][0]) {
dp[score] = [dp[score - 50][0] + 1, dp[score - 50][1] + 1];
}
}
return dp[target];
}