#K12091. Peak Energy Level

    ID: 23613 Type: Default 1000ms 256MiB

Peak Energy Level

Peak Energy Level

You are given n energy pulses. Each pulse is represented by a triplet \( (s_i, e_i, p_i) \), where:

  • \( s_i \) is the start time of the pulse,
  • \( e_i \) is the end time of the pulse, and
  • \( p_i \) is the energy level contributed by the pulse.

At any given moment, the total energy is the sum of energy levels for all pulses that are active (i.e. \( s_i \le t < e_i \)). Your task is to compute the peak energy level observed over the entire time span.

Note: The energy of a pulse starts contributing at its start time \( s_i \) and stops just before the end time \( e_i \). Formally, the contribution of a pulse at time \( t \) is:

\( \text{contribution}(t) = \begin{cases} p_i & \text{if } s_i \le t < e_i, \\ 0 & \text{otherwise.} \end{cases} \)

inputFormat

The input is read from standard input (stdin) and has the following format:

n
s₁ e₁ p₁
s₂ e₂ p₂
... 
sₙ eₙ pₙ

Here, n is an integer representing the number of pulses, and each following line contains three integers separated by spaces representing the start time, end time, and energy level respectively.

outputFormat

Output a single integer to standard output (stdout), which is the maximum (peak) energy level observed over all time slices.

## sample
3
1 4 10
2 5 7
3 6 5
22