Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def continuous_frost(n, temperature_ranges):
- longest_frost = 0
- current_frost = 0
- start_day = -1
- best_start_day = -1
- for i in range(n):
- min_temp, max_temp = temperature_ranges[i]
- if max_temp < 0: # Continuous frost condition
- if current_frost == 0:
- start_day = i + 1
- current_frost += 1
- else:
- if current_frost > longest_frost:
- longest_frost = current_frost
- best_start_day = start_day
- current_frost = 0
- if current_frost > longest_frost:
- longest_frost = current_frost
- best_start_day = start_day
- if longest_frost == 0:
- return -1
- else:
- return best_start_day
- n = 5
- temperature_ranges = [(-5, 2), (-6, -4), (-3, -2), (-8, -5), (-2, 1)]
- result = continuous_frost(n, temperature_ranges)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment