Skip to content
🤔prompts chat🧠
🔍
question:def count_students_receiving_prize(n: int, k: int) -> int: Returns the number of students who will receive the prize. :param n: Total number of students :param k: Divisor to determine prize eligibility :return: Number of students receiving the prize >>> count_students_receiving_prize(10, 3) 3 >>> count_students_receiving_prize(1, 1) 1

answer:def count_students_receiving_prize(n, k): Returns the number of students who will receive the prize. :param n: Total number of students :param k: Divisor to determine prize eligibility :return: Number of students receiving the prize return n // k

question:def max_profit(f, m, prices): Calculate the maximum profit that can be achieved by selling each fruit in the market that offers the highest price. Parameters: f (int): Number of fruits m (int): Number of markets prices (list of list of int): Price list with f lists of m integers Returns: int: Maximum profit Example: >>> max_profit(3, 3, [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ]) == 18 pass from solution import max_profit def test_example(): prices = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_profit(3, 3, prices) == 18 def test_single_fruit_single_market(): prices = [ [5] ] assert max_profit(1, 1, prices) == 5 def test_multiple_fruits_single_market(): prices = [ [15], [10], [20] ] assert max_profit(3, 1, prices) == 45 def test_single_fruit_multiple_markets(): prices = [ [1, 2, 3, 4, 5] ] assert max_profit(1, 5, prices) == 5 def test_random_prices(): prices = [ [10, 20, 30], [5, 15, 25], [1, 11, 21] ] assert max_profit(3, 3, prices) == 76 def test_equal_prices(): prices = [ [2, 2, 2], [2, 2, 2], [2, 2, 2] ] assert max_profit(3, 3, prices) == 6 def test_large_input(): prices = [[i + j for j in range(1000)] for i in range(1000)] assert max_profit(1000, 1000, prices) == sum(999 + i for i in range(1000))

answer:def max_profit(f, m, prices): Calculate the maximum profit that can be achieved by selling each fruit in the market that offers the highest price. Parameters: f (int): Number of fruits m (int): Number of markets prices (list of list of int): Price list with f lists of m integers Returns: int: Maximum profit max_profit = 0 for fruit_prices in prices: max_profit += max(fruit_prices) return max_profit

question:from typing import List, Tuple def count_main_routes(N: int, M: int, T: int, portals: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]: Given the list of one-way portals connecting pairs of planets, determine the number of different main routes from planet S to planet D. If there is no route from S to D, the number of different main routes should be zero. Args: N (int): Number of planets. M (int): Number of one-way portals. T (int): Number of test cases. portals (List[Tuple[int, int]]): List of one-way portals where each portal connects a pair of planets (u, v). queries (List[Tuple[int, int]]): List of queries where each query consists of two integers S and D. Returns: List[int]: List of integers representing the number of different main routes for each query. >>> count_main_routes(6, 7, 2, [(1, 2), (2, 3), (1, 3), (3, 4), (4, 5), (5, 6), (3, 6)], [(1, 5), (1, 6)]) [1, 1] >>> count_main_routes(5, 4, 3, [(1, 2), (1, 3), (3, 4), (4, 5)], [(1, 4), (1, 5), (2, 5)]) [1, 1, 0]

answer:from collections import defaultdict, deque def count_main_routes(N, M, T, portals, queries): def bfs_distance_and_count(S): # BFS to find shortest paths and path count distances = [-1] * (N + 1) path_counts = [0] * (N + 1) queue = deque([S]) distances[S] = 0 path_counts[S] = 1 while queue: planet = queue.popleft() for neighbor in graph[planet]: if distances[neighbor] == -1: # unvisited planet distances[neighbor] = distances[planet] + 1 path_counts[neighbor] = path_counts[planet] queue.append(neighbor) elif distances[neighbor] == distances[planet] + 1: # another shortest path found path_counts[neighbor] += path_counts[planet] return distances, path_counts # Create the graph graph = defaultdict(list) for u, v in portals: graph[u].append(v) results = [] for S, D in queries: distances, path_counts = bfs_distance_and_count(S) # If D is unreachable, path_counts[D] will be 0 results.append(path_counts[D] if distances[D] != -1 else 0) return results # Main logic to read input and produce output (For interactive use, commented out for unit tests) # if __name__ == "__main__": # N, M, T = map(int, input().split()) # portals = [tuple(map(int, input().split())) for _ in range(M)] # queries = [tuple(map(int, input().split())) for _ in range(T)] # results = count_main_routes(N, M, T, portals, queries) # for result in results: # print(result)

question:def can_complete_mission(P: int, n: int, terrains: List[int]) -> str: Determines if the robot can complete its mission without running out of power at any point. Parameters: P (int): Initial power level of the robot. n (int): Number of terrains to traverse. terrains (list of int): List indicating the effect of each terrain on the robot's power level. Returns: str: "Yes" if the robot can complete its mission without the power level dropping to zero or below at any point, otherwise "No". >>> can_complete_mission(10, 5, [-2, 3, -5, 1, -3]) 'Yes' >>> can_complete_mission(10, 5, [-2, 3, -10, 1, -3]) 'No'

answer:def can_complete_mission(P, n, terrains): Determines if the robot can complete its mission without running out of power at any point. Parameters: P (int): Initial power level of the robot. n (int): Number of terrains to traverse. terrains (list of int): List indicating the effect of each terrain on the robot's power level. Returns: str: "Yes" if the robot can complete its mission without the power level dropping to zero or below at any point, otherwise "No". current_power = P for effect in terrains: current_power += effect if current_power <= 0: return "No" return "Yes"

Released under the chat License.

has loaded