A round-robin tournament is being held in Chefland among N teams numbered 1,2,…,N1,2,…,N. Every team play with all other teams exactlyexactly once. All games have only two possible results – win or loss. A win yields 22 points to the winning team while a loss yields no points. What is the maximum number of points a team finishing at the KthKth position can score?
Note:Note: If two teams have the same points then the team with the higher team number achieves the better rank.
Input Format
- First line will contain TT, number of testcases. Then the testcases follow.
- Each testcase contains a single line of input, two space-separated integers N,KN,K.
Output Format
For each testcase, output in a single line an integer – the maximum points the team ranked KK in the round-robin tournament can score.
Constraints
- 1≤T≤1051≤T≤105
- 1≤K≤N≤1091≤K≤N≤109
Sample Input 1
3
3 3
4 1
7 4
Sample Output 1
2
6
8
Explanation
Test Case 11: There are 33 teams in the tournament. The maximum score will be achieved by the team coming 3rd3rd when all teams win 11 matches and lose the other one. Hence the maximum possible score will be 2(2⋅1)2(2⋅1) points.
Test Case 22: There are 44 teams in the tournament. The maximum score will be achieved by the team coming 1st1st when they beat all teams in the tournament. Hence the maximum possible score will be 6(2⋅3)6(2⋅3) points.
Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n, k;
cin>>n>>k;
int res = (2*n-k-1)/2;
cout<<2*res<<endl;
}
return 0;
}
0 Comments