Codeforces1313 B. Different Rules(找规律)

本文探讨了一个竞赛编程场景,其中一名选手在两轮比赛中获得特定排名,目标是确定该选手可能的最高和最低总体排名。通过分析所有参与者两轮比赛排名总和的范围,提出了一个简洁的算法来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:

Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n 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 x−thx-thxth place and in the second round — y−thy-thyth place. Then the total score of the participant A is sum x+yx+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 i from 1 to n exactly one participant took i-th place in first round and exactly one participant took i−thi-thith place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got x-th place in first round and y-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 t(1≤t≤100)t (1≤t≤100)t(1t100) — the number of test cases to solve.

Each of the following t lines contains integers n,x,y(1≤n≤109,1≤x,y≤n)n, x, y (1≤n≤10^9, 1≤x,y≤n)n,x,y(1n109,1x,yn) — 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

1
5 1 3

output

1 3

input

1
6 3 4

output

2 6

Note

Explanation for the first example:

Suppose there were 555 participants A-E. Let’s denote Nikolay as A. The the most favorable results for Nikolay could look as follows:
在这里插入图片描述

However, the results of the Olympiad could also look like this:
在这里插入图片描述

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

题意:

nnn 个人参加比赛一共两场,给出一个人的两场比赛排名为 x,yx,yx,y,问这个 人的最高排名和最低排名。
全部人的两场排名之和范围是 2 2n2~2n2 2n

  • 先求最高排名,如果这个人 x+y<n−1x+y<n-1x+y<n1 ,那么他的总排名肯定可以最高为1,如果大于的话那最低排名就只能是 nnn
  • 最低排名的话,如果 x+y<n+1x+y<n+1x+y<n+1,那就是 x+y−1x+y-1x+y1,否则就是 nnn
    这个很好推啊,不知道咋卡了怎么多人,我一开始写了好几个判断,后来化简一下就是两个式子。

AC代码:

const int N = 25;
int n, m;
int t;
int a, b, c;
int x, y;
int pos;
int res, tmp, ans1, ans2;
int main()
{
    sd(t);
    while (t--)
    {
        sddd(n, x, y);
        res = x + y;
        ans1 = min(max(res + 1 - n, 1), n);
        ans2 = min(res - 1, n);
        pdd(ans1, ans2);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值