Codeforces Round #622 (Div. 2)—B—Different Rules

B. Different Rules

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be nn participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.

Suppose in the first round participant A took xx-th place and in the second round — yy-th place. Then the total score of the participant A is sum x+yx+y. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every ii from 11 to nn exactly one participant took ii-th place in first round and exactly one participant took ii-th place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got xx-th place in first round and yy-th place in the second round. Nikolay doesn't know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

Input

The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases to solve.

Each of the following tt lines contains integers nn, xx, yy (1≤n≤1091≤n≤109, 1≤x,y≤n1≤x,y≤n) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Output

Print two integers — the minimum and maximum possible overall place Nikolay could take.

Examples

input

Copy

1
5 1 3

output

Copy

1 3

input

Copy

1
6 3 4

output

Copy

2 6

Note

Explanation for the first example:

Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows:

58f5f96bd3456229d518aa232429001f8449fa3b.pnguploading.4e448015.gif正在上传…重新上传取消

However, the results of the Olympiad could also look like this:

ab592ad82b00462bdb6900cf14f437bf8f0e6953.pnguploading.4e448015.gif正在上传…重新上传取消

In the first case Nikolay would have taken first place, and in the second — third place.

思路:

代码很简单,主要是证明,我的想法可能复杂了,也许两句话就能推出来了,我用的笨的方法;

首先对于最小的名次,只需要考虑x左边和y左边能够成功匹配大于(x+y)的有多少即可;

对于x左边的数来说,只有y+1右边的数与之匹配才能大于(x+y);所以成功匹配后剩余(x-1-(n-y-1))个数没有匹配成功;

对于y左边的数来说,只有x+1右边的数与之匹配才能大于(x+y);所以成功匹配后剩余(y-1-(n-x-1))个数没有匹配成功;

总的来说上线一共有2(x+y-n)个数没有匹配成功,也就是(x+y-n)个人;加上A本身是(x+y-n)+1;注意临界值即可;

然后讨论最大的名次;只需要考虑有多少对数相加的和等于x+y;可以自己画一下证明,一共有x+y-1对;

AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin >>t;
	while(t--)
	{
		int n,x,y;
		cin >>n>>x>>y;
		cout <<min(max(x+y-n+1,1),n)<<" "<<min(x+y-1,n)<<endl;
	}
}
发布了209 篇原创文章 · 获赞 40 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43872728/article/details/104470333