Educational Codeforces Round 1303B #82 (Rated for Div. 2) B. Perfect Keyboard
Your company was appointed to lay new asphalt on the highway of length 𝑛. 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 𝑔 days when the climate is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next 𝑏 days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again 𝑔 good days, 𝑏 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,…,𝑔 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 𝑛=5 then at least 3 units of the highway should have high quality; if 𝑛=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 𝑇 (1≤𝑇≤104) — the number of test cases.
Next 𝑇 lines contain test cases — one per line. Each line contains three integers 𝑛, 𝑔 and 𝑏 (1≤𝑛,𝑔,𝑏≤109) — the length of the highway and the number of good and bad days respectively.
Output
Print 𝑇 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.
Example
input
3
5 1 1
8 10 10
1000000 1 1000000
output
5
8
499999500000
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.
有n天需要工作。有这么一个规则,连续g天是好天气,再连续b天是坏天气。如果在好天气工作可以做好,要求至少有n/2向上取整天数做好的个数。你可以选择休息,但是有n天的工作等着你,也就是说随便你休息多少天,但是至少要n天工作。求最小的天数完成工作。
注意:n天的工作量是必须完成的,不管做的好还是做不好。见第二个样例。
/// @author zhaolu
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <sstream>
#include <algorithm>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repe(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define MOD (1000000007)
#define MAX (100000)
#define LEN (MAX+10)
typedef long long ll;
using namespace std;
int t;
long long n,g,b,tmp;
int sum;
long long ans;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld",&n,&g,&b);
tmp=n;
n=(n+1)>>1;
if(n%g==0) ans=(g+b)*(n/g)-b;
else ans=(g+b)*(n/g)+n%g;
printf("%lld\n",max(ans,tmp));
}
return 0;
}