特技表演 (APCS 2024-06)

Points 100 1.0s 256M

有一個城鎮有 \(n\) 棟高樓,樓高分別為 \(h_1, h_2, \ldots, h_n\)。市長想在城鎮中心舉辦高空特技表演,該表演會從某棟大樓上朝右側滑翔至地面。為了表演人員的安全,滑翔路徑經過的樓高必須越來越低(嚴格遞減)。請找出最長的滑翔路徑長度。

換句話說,請找出一段連續的大樓 \(h_i, h_{i+1}, \ldots, h_j\),滿足 \(h_i > h_{i+1} > \cdots > h_j\),並使這段的棟數最多;輸出這個最多的棟數。

輸入格式

第一行有一個正整數 \(n\)。

第二行有 \(n\) 個正整數 \(h_1, h_2, \ldots, h_n\),代表樓高。

限制

  • \(5 \le n \le 100\)
  • \(1 \le h_i \le 1000\)

輸出格式

輸出最長滑翔路徑的長度(最多連續嚴格遞減的棟數)。

評分說明

每一筆測試資料的執行時間限制均為 \(1\) 秒,依正確通過的測試資料筆數給分。其中:

  • 第 1 子題組(\(60\) 分):\(n = 5\)。
  • 第 2 子題組(\(40\) 分):無限制。

範例輸入 1

5
6 2 5 3 1

範例輸出 1

3

(說明)最長嚴格遞減的連續段是 \(5, 3, 1\),長度為 \(3\)。

範例輸入 2

10
31 41 97 93 23 89 59 26 15 58

範例輸出 2

4

(說明)最長嚴格遞減的連續段是 \(89, 59, 26, 15\),長度為 \(4\)。

題目來源

APCS 2024 年 6 月實作題第 1 題。

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test and sample test share the sandbox; about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test and sample test both have a 15 second wall-clock cap (the official judge still uses the problem time limit)
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.