Electricity Bill by Slabs

Medium ⏱ 12 min 57% acceptance ★★★★★ 4.6
Units are billed in slabs: first 100 units at ₹3, next 100 at ₹5, next 300 at ₹7, beyond 500 at ₹9 — plus a fixed ₹50 meter charge. Write electricity_bill(units) computing the total, slab by slab (the same marginal structure as income tax).

Examples

Example 1
Input
electricity_bill(250)
Output
1900
Explanation

300 + 500 + 1050 for the consumed slabs, +50 fixed.

Constraints

  • Marginal slabs.
  • Fixed charge always applies.

Topics

Business Logicslab billing

Companies

Tata PowerAdani EnergyBSES

Hints

Hint 1

Reuse the band-walking pattern.

Hint 2

min(remaining, slab_width) per slab.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.