Guest User

Untitled

a guest
Jan 8th, 2025
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def continuous_frost(n, temperature_ranges):
  2.     longest_frost = 0
  3.     current_frost = 0
  4.     start_day = -1
  5.     best_start_day = -1
  6.  
  7.     for i in range(n):
  8.         min_temp, max_temp = temperature_ranges[i]
  9.  
  10.         if max_temp < 0:  # Continuous frost condition
  11.             if current_frost == 0:
  12.                 start_day = i + 1
  13.             current_frost += 1
  14.         else:
  15.             if current_frost > longest_frost:
  16.                 longest_frost = current_frost
  17.                 best_start_day = start_day
  18.             current_frost = 0
  19.  
  20.     if current_frost > longest_frost:
  21.         longest_frost = current_frost
  22.         best_start_day = start_day
  23.  
  24.     if longest_frost == 0:
  25.         return -1
  26.     else:
  27.         return best_start_day
  28.  
  29. n = 5
  30. temperature_ranges = [(-5, 2), (-6, -4), (-3, -2), (-8, -5), (-2, 1)]
  31.  
  32. result = continuous_frost(n, temperature_ranges)
  33. print(result)
Advertisement
Add Comment
Please, Sign In to add comment