题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; function getLongest(arr){ let dp = Array(arr.length).fill(1); for(let i = 0;i<arr.length ;i++){ for(let j=0;j<i;j++){ if(arr[i] > arr[j]){ dp[i] = Math.max(dp[i],dp[j]+1) } } } return dp; } void async function () { // Write your code here let peopleTotal = await readline(); peopleTotal = peopleTotal*1; let line = await readline(); let data = line.split(' ').map(height=>height*1); let leftToRight = getLongest(data); let rightToLeft = getLongest(data.reverse()).reverse(); let rst = Math.max(...leftToRight.map((item,index)=>(item+rightToLeft[index]))) console.log(peopleTotal-rst+1); }()