Final Exam (HDU-6651)

Problem Description

Final Exam is coming! Cuber QQ has now one night to prepare for tomorrow's exam.

The exam will be a exam of problems sharing altogether m points. Cuber QQ doesn't know about the exact distribution. Of course, different problems might have different points; in some extreme cases, some problems might worth 0 points, or all m points. Points must be integers; a problem cannot have 0.5 point.

What he knows, is that, these n problems will be about n totally different topics. For example, one could be testing your understanding of Dynamic Programming, another might be about history of China in 19th century. So he has to divide your night to prepare each of these topics separately. Also, if one problem is worth x points in tomorrow's exam, it takes at least x+1 hours to prepare everything you need for examination. If he spends less than x+1 hours preparing, he shall fail at this problem.

Cuber QQ's goal, strangely, is not to take as much points as possible, but to solve at least k problems no matter how the examination paper looks like, to get away from his parents' scoldings. So he wonders how many hours at least he needs to achieve this goal.

Input

The first line of the input is an integer t (1≤t≤20 000), denoting the number of test cases.

Each test case are three space-separated integers n,m,k (0≤m≤109, 1≤k≤n≤109). 

Output

For each test case, output the number of hours Cuber QQ needs.

Sample Input

2
1 10 1
10 109 10

Sample Output

11
1100

The meaning of problems: t sets of data, each given n, m, three numbers k, n representatives question, divided into a total of m of these problems, for each question, assuming that the score is x, then to review x +1 hours to get this sub-theme, ask questions to make k a minimum review time

Ideas:

Questions can be understood that there are two sequences a, b, where a sequence value is unknown, but the sum of m, b the number of sequences to be filled, so that there is at least k b [i] satisfies b [i] = a [i] +1

Each number of a [i] is a sequence of 0 ~ m may be arbitrarily set as long as the sum total is equal to m, if a b do not want to win, it will at least let the k-1 and b k 0 before -1 large compared to the rest of the just let b (n- (k-1)) is less than a number of the remaining (n- (k-1)) to the number of

Thus, a maximum number can take m / (n- (k-1)) + 1

Conversely, as long as b k-1 number of taken m / (n- (k-1)) + 1, in order to ensure the final win, taking the number of the last m + 1, the rest set to 0, then it must be The number of eligible k

So that when a k-th small take optimal strategy, k-1 zeros large compared with the number k-1 in a front B, b k-1 there is compliance with the number of conditions, b in a number of the remaining will certainly larger than a certain number of remaining, hence the number of eligible k

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;}
LL quickPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;}
LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-10;
const int MOD = 998244353;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        LL n, m, k;
        scanf("%lld%lld%lld", &n, &m, &k);
        LL sum = 0;
        sum = (k - 1) * (m / (n - (k - 1)) + 1);
        sum += (m + 1);
        printf("%lld\n", sum);
    }
    return 0;
}

 

Released 1871 original articles · won praise 702 · Views 1.94 million +

Guess you like

Origin blog.csdn.net/u011815404/article/details/102504006