National Project (Codeforces 1303B)
Tags: Math, math

Your company was appointed to lay new asphalt on the highway of length $$$n$$$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are $$$g$$$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $$$b$$$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $$$g$$$ good days, $$$b$$$ bad days and so on.You can be sure that you start repairing at the start of a good season, in other words, days $$$1, 2, \dots, g$$$ are good.You don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $$$n = 5$$$ then at least $$$3$$$ units of the highway should have high quality; if $$$n = 4$$$ then at least $$$2$$$ units should have high quality.What is the minimum number of days is needed to finish the repair of the whole highway?

Input: The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases.Next $$$T$$$ lines contain test cases — one per line. Each line contains three integers $$$n$$$, $$$g$$$ and $$$b$$$ ($$$1 \le n, g, b \le 10^9$$$) — the length of the highway and the number of good and bad days respectively.

Output: Print $$$T$$$ integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

Note: In the first test case, you can just lay new asphalt each day, since days $$$1, 3, 5$$$ are good.In the second test case, you can also lay new asphalt each day, since days $$$1$$$-$$$8$$$ are good.

Sample Inputs:
3
5 1 1
8 10 10
1000000 1 1000000

Sample Outputs:
5
8
499999500000

Solution (Python):
t = int(input())
r = []
import math
for i in range(t):
    y = list(map(int, input().split()))
    n = y[0]
    g = y[1]
    b = y[2]
    a = math.ceil(n / 2)
    c = math.ceil(a / g)
    e = c - 1
    f = n - a
    d = e * b
    if d >= f:
        Tl = a + d
    else:
        Tl = n
    r.append(Tl)
for i in range(len(r)):
    print(r[i])

Solution (Python):
import sys
input = sys.stdin.readline

def readList():
    return list(map(int, input().split()))

def readInt():
    return int(input())

def readInts():
    return map(int, input().split())

def readStr():
    return input().strip()

def solve():
    (n, g, b) = readInts()
    ans = n
    if g < b:
        (d, rg) = (n // (2 * g), min(n % (2 * g), g))
        (rb, r) = (n % (2 * g) - rg, d * (b - g))
        ans = (g + b) * d + rg + rb
        if rg == 0:
            ans -= b - g + min(g, max(0, d - 1) * (b - g))
        elif rb == 0:
            ans -= min(r, rg // 2)
        else:
            ans -= min(rb, r) + min((g - rb) // 2, r - rb) if rb < r else min(rb, r)
    return ans
for _ in range(int(input())):
    print(solve())

Solution (Python):
from math import ceil
testcases = int(input())
results = []
for i in range(testcases):
    [n, g, b] = [int(num) for num in input().split()]
    threshold = ceil(n / 2)
    min_cycles = threshold // g
    result = (min_cycles - 1) * (g + b) + g
    if min_cycles * g < threshold:
        result += b + (threshold - min_cycles * g)
    if result < n:
        result = n
    results.append(int(result))
for i in results:
    print(i)