Please log in to access this page.

Chef to reach checkpoint 0

Added: 2025-09-12 22:38:38

Question Image

Chef to reach checkpoint 0

Answer

✏️ Edit
t = int(input())

for _ in range(t):
    n, v = map(int, input().split())

    # Maximum cost: always refill 1 liter at every checkpoint
    max_cost = (n - 1) * n // 2

    if v >= n - 1:
        # Can reach in one full refill at checkpoint 1
        min_cost = n - 1
    else:
        # First refill full tank at checkpoint 1 (cost 1 * v)
        min_cost = v
        # Remaining liters needed
        remaining = n - 1 - v
        # Need to refill 1 liter at each next checkpoint: 2, 3, ..., (2 + remaining - 1)
        start = 2
        end = 2 + remaining - 1
        min_cost += (end * (end + 1)) // 2 - ((start - 1) * start) // 2

    print(max_cost, min_cost)