Tap here to switch tabs
Problem
Submissions

Problem: Minimum Energy to Maintain Brightness

Try to solve the Minimum Energy to Maintain Brightness problem.

Statement

You are given an integer n representing the number of positions on a line, indexed from 00 to n −1- 1, and an integer brightness representing the minimum number of positions that must be illuminated.

Placing a light bulb at position p illuminates position p as well as its adjacent positions p −1- 1 and p +1+ 1 (if they exist within the line).

You are also given a 22D integer array intervals, where intervals[i] = [start_i, end_i] represents an inclusive active time interval [[ start_i, end_i ]] of length end_i −- start_i +1+ 1.

Each light bulb consumes 11 unit of energy per unit of time while active. The total active time is the total length of the union of all intervals in intervals.

Return the minimum total energy required to illuminate at least brightness positions across the entire active time.

Constraints:

  • 1≤1 \leq n ≤106\leq 10^6

  • 1≤1 \leq brightness ≤\leq n

  • 1≤1 \leq intervals.length ≤105\leq 10^5

  • intervals[i] == [start_i, end_i]

  • 0≤0 \leq start_i ≤\leq end_i ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Energy to Maintain Brightness

Try to solve the Minimum Energy to Maintain Brightness problem.

Statement

You are given an integer n representing the number of positions on a line, indexed from 00 to n −1- 1, and an integer brightness representing the minimum number of positions that must be illuminated.

Placing a light bulb at position p illuminates position p as well as its adjacent positions p −1- 1 and p +1+ 1 (if they exist within the line).

You are also given a 22D integer array intervals, where intervals[i] = [start_i, end_i] represents an inclusive active time interval [[ start_i, end_i ]] of length end_i −- start_i +1+ 1.

Each light bulb consumes 11 unit of energy per unit of time while active. The total active time is the total length of the union of all intervals in intervals.

Return the minimum total energy required to illuminate at least brightness positions across the entire active time.

Constraints:

  • 1≤1 \leq n ≤106\leq 10^6

  • 1≤1 \leq brightness ≤\leq n

  • 1≤1 \leq intervals.length ≤105\leq 10^5

  • intervals[i] == [start_i, end_i]

  • 0≤0 \leq start_i ≤\leq end_i ≤109\leq 10^9