题解 | #牛牛吃草#
牛牛吃草
https://www.nowcoder.com/practice/f05254f070944ff792c0dfefabd94fec
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here const len = await readline() const w = (await readline()).split(' ').map(Number) const a = (await readline()).split(' ').map(Number) const res = [...w] let ans = 0 const canReach = (j, i) => { if ((i-j)%a[j] === 0) { return res[j] } else { return false } } for (let i=1; i<len; i++) { let maxJump = 0 for (let j=0; j<i;j++) { if (canReach(j, i)) { maxJump = Math.max(maxJump, canReach(j, i) + res[i]) } } res[i] = Math.max(maxJump, res[i]) if (res[i]>ans) { ans = res[i] } } console.log(ans) }()