codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1303B.md (2106B)


      1 Source: https://codeforces.com/problemset/problem/1303/B
      2 
      3 B. National Project
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 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.
     28 
     29 What is the minimum number of days is needed to finish the repair of the whole highway?
     30 
     31 Input
     32 
     33 The first line contains a single integer $T$ ($1 \le T \le 10^4$) — the number of test cases.
     34 
     35 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.
     36 
     37 Output
     38 
     39 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.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 3
     47 5 1 1
     48 8 10 10
     49 1000000 1 1000000
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 5
     56 8
     57 499999500000
     58 ```
     59 
     60 Note
     61 
     62 In the first test case, you can just lay new asphalt each day, since days $1, 3, 5$ are good.
     63 
     64 In the second test case, you can also lay new asphalt each day, since days $1$-$8$ are good.