Citadel OA
unknown
python
a year ago
784 B
23
Indexable
import math def min_operations(executionTime, x, y): def can_complete_in_k_operations(K): total_major_operations = 0 for time in executionTime: if time <= y * K: major_needed = 0 else: time_remaining_after_minor_ops = time - y * K major_needed = math.ceil((time_remaining_after_minor_ops) / (x - y)) total_major_operations += major_needed if total_major_operations > K: return False return total_major_operations <= K low, high = 1, max(executionTime) // y while low <= high: mid = (low + high) // 2 if can_complete_in_k_operations(mid): high = mid - 1 else: low = mid + 1 return low
Editor is loading...
Leave a Comment