裝飲料 (APCS 2024-10)

Points 100 1.0s 256M

有一個杯子,可將其體積視為由兩個長方體組成(如下圖):下方的長方體底面積為 \(w_1 \times w_1 ~\mathrm{cm^2}\)、高為 \(h_1 ~\mathrm{cm}\);上方的長方體底面積為 \(w_2 \times w_2 ~\mathrm{cm^2}\)、高為 \(h_2 ~\mathrm{cm}\)。

一開始杯子為空。要裝 \(n\) 次飲料,每一次裝 \(v ~\mathrm{cm^3}\) 容量的飲料;當水杯滿時,水位不再上升。請問這 \(n\) 次倒飲料中,水位上升變化量最高是幾 cm。

輸入格式

第一行有一個正整數 \(n\),代表要裝 \(n\) 次飲料。

第二行有 \(4\) 個正整數 \(w_1, w_2, h_1, h_2\),代表杯子的寬度與高度。

第三行有 \(n\) 個正整數,代表每次裝飲料的容量。

限制

  • \(1 \le n \le 10\)
  • \(1 \le w_1, w_2, h_1, h_2 \le 50\)
  • 保證每次倒飲料後的水位上升量都是整數

輸出格式

輸出這 \(n\) 次倒飲料中,水位上升變化量最大的高度(單位 cm)。

評分說明

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

  • 第 1 子題組(\(60\) 分):\(n = 1\)(即答案為倒水後的水位高度)。
  • 第 2 子題組(\(40\) 分):無限制。

範例輸入 1

1
4 6 8 5
200

範例輸出 1

10

(說明)下方體積 \(4^2 \times 8 = 128\)。倒入 \(200\) 後超過 \(128\),水位 \(= 8 + (200 - 128)/6^2 = 8 + 2 = 10\)。

範例輸入 2

2
5 10 12 8
400 600

範例輸出 2

13

(說明)下方體積 \(5^2 \times 12 = 300\)。第一次倒 \(400\):水位 \(= 12 + (400 - 300)/10^2 = 13\),上升 \(13\);第二次累積 \(1000\):水位 \(= 12 + (1000 - 300)/100 = 19\),上升 \(6\)。最大上升量為 \(13\)。

範例輸入 3

5
16 44 28 17
2560 1280 1536 1024 10448

範例輸出 3

10

題目來源

APCS 2024 年 10 月實作題第 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.