Highway Billboard Leasing accepts a solution that greedily leases the largest offer first

オープン
#868 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@PeteChiang1211 がすでに取り組んでいます。

2026年11月26日 から。

評価

この issue はまだ評価されていません。

説明

A solution that sorts the sites by offer and leases each one whose neighbours are still free passes all five house-robber cases, although it is not correct.

Wrong solution (Python):

class Solution:
    def bestLeaseRevenue(self, nums):
        taken, total = set(), 0
        for i in sorted(range(len(nums)), key=lambda i: -nums[i]):
            if i - 1 not in taken and i + 1 not in taken:
                taken.add(i)
                total += nums[i]
        return total

It returns the right answer for every case in problem-bank/judges.json ([1, 2, 3, 1], [2, 7, 9, 3, 1], [5], [0, 0, 0], [2, 1, 1, 2]), because in each of them the largest offer belongs to an optimal set.

It fails when the largest offer sits between two smaller offers whose sum is bigger:

nums expected greedy
[2, 3, 2] 4 3
[4, 5, 4, 1] 8 6

Both inputs are inside the stated domain (1 to 100 sites, offers 0 to 400).

Proposed fix: add a case such as [2, 3, 2] (label along the lines of "largest offer is not in the best set") to the judge, and a test that pins the greedy solution to that case so removing the case fails the test, following the jump-game and stock III judge fixes. I would like to work on this.

主要言語
Rust
スター
236
フォーク
153
平均マージ
1日 9時間
マージ済み PR(30日)
187

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sysprog21/codetrial のほかの issue

sysprog21/codetrial の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。