C. Vasilije in Cacak

文章讲述两位程序员在塞尔维亚城市Cacak提出的问题,涉及找出k个1到n之间的整数使其和等于x的解法。代码展示了如何处理多组测试数据并输出结果。
摘要由CSDN通过智能技术生成

Aca and Milovan, two fellow competitive programmers, decided to give Vasilije a problem to test his skills.

Vasilije is given three positive integers: nn, kk, and xx, and he has to determine if he can choose kk distinct integers between 11 and nn, such that their sum is equal to xx.

Since Vasilije is now in the weirdest city in Serbia where Aca and Milovan live, Cacak, the problem seems weird to him. So he needs your help with this problem.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The only line of each test case contains three integers nn, kk and xx (1≤n≤2⋅1051≤n≤2⋅105, 1≤k≤n1≤k≤n, 1≤x≤4⋅10101≤x≤4⋅1010) — the maximum element he can choose, the number of elements he can choose and the sum he has to reach.

Note that the sum of nn over all test cases may exceed 2⋅1052⋅105.

Output

For each test case output one line: "YES", if it is possible to choose kk distinct integers between 11 and nn, such that their sum is equal to xx, and "NO", if it isn't.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

Example


input

12
5 3 10
5 3 3
10 10 55
6 5 20
2 1 26
187856 87856 2609202300
200000 190000 19000000000
28 5 2004
2 2 2006
9 6 40
47202 32455 613407217
185977 145541 15770805980

output

YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES

Code

#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0);

    int _;
    cin >> _;

    while (_) {
        long long n, k, x;
        cin >> n >> k >> x;

        // 使用条件表达式来判断是否输出 "YES" 或 "NO"
        cout << ((x >= k * (k + 1) / 2 && x <= k * (n + n - k + 1) / 2) ? "YES" : "NO") << endl;
        
        // 这里减少了一次无用的输入,将 _ 自减来控制循环次数
        _--;
    }

    return 0;
}

Conclusion 

        上面的代码是一个循环处理多个测试用例的程序。它首先从输入中读取一个整数 _,表示待处理的测试用例数量。
        然后,在进入循环之前,通过设置 ios::sync_with_stdio(0); 和 cout.tie(0); 来优化输入输出流的同步。
        接下来,通过一个 while 循环来处理每个测试用例。在每次循环迭代中,从输入中读取三个整数 n、k 和 x,它们分别表示测试用例的参数。
        接下来,通过使用条件表达式 (x &gt;= k * (k + 1) / 2 &amp;&amp; x &lt;= k * (n + n - k + 1) / 2) 来判断条件是否为真。如果条件成立,则输出 "YES",否则输出 "NO"。这里用到了数学计算,判断变量 x 是否在某个范围内。
        最后,通过将 _ 变量自减来控制循环次数,以处理所有的测试用例。
        总的来说,这段代码通过循环处理多个测试用例,根据给定的条件进行判断并输出结果。代码逻辑相对简单,主要用到了条件判断和输入输出操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向阳而生__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值