Help needed for https://cses.fi/problemset/task/1163 Traffic Lights

Правка en2, от pranshukas, 2020-08-14 10:58:29

I need help with this Problem Traffic Lights.**CSES Problem Set** under Sorting and Searching. I thought of an approach that

-> create a set add elements at every step,

-> Traverse the set and take the difference and take the maximum out of it.

-> display maximum at every step.

But I think this is a very naive approach and Time Complexity would be O(n^2) and n can be up to 10^5, so most of my Test Cases are giving TLE.

I am not able to think of another approach. Can Anyone give me a hint, how should I approach it.

Теги #sorting, c++ 11, #cses, #binary search

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский pranshukas 2020-08-14 11:00:02 13
en3 Английский pranshukas 2020-08-14 10:58:54 1 Tiny change: 'ask/1163).**CSES Pro' -> 'ask/1163). **CSES Pro'
en2 Английский pranshukas 2020-08-14 10:58:29 2 Tiny change: 'k/1163).** CSES Probl' -> 'k/1163).**CSES Probl'
en1 Английский pranshukas 2020-08-14 10:57:47 649 Initial revision (published)