每日一题 第九十三期 Codeforces Round 900 (Div. 3)

文章讲述了两位程序员设计了一个关于在一定范围内选择k个整数使其和等于x的问题,Vasilije需要帮助。给出了测试用例和C++代码示例。
摘要由CSDN通过智能技术生成

C. Vasilije in Cacak

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

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

Vasilije is given three positive integers: n n n, k k k, and x x x, and he has to determine if he can choose k k k distinct integers between 1 1 1 and n n n, such that their sum is equal to x x x.

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 t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The only line of each test case contains three integers n n n, k k k and x x x ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105, 1 ≤ k ≤ n 1 \le k \le n 1kn, 1 ≤ x ≤ 4 ⋅ 1 0 10 1 \le x \le 4 \cdot 10^{10} 1x41010) — 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 n n n over all test cases may exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case output one line: “YES”, if it is possible to choose k k k distinct integers between 1 1 1 and n n n, such that their sum is equal to x x x, 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
inputCopy
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
outputCopy
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES

Note

In the first test case n = 5 ,   k = 3 ,   x = 10 n = 5,\ k=3,\ x=10 n=5, k=3, x=10, so we can choose the numbers: 2 2 2, 3 3 3, 5 5 5, whose sum is 10 10 10, so the answer is “YES”.

In the second test case n = 5 ,   k = 3 ,   x = 3 n = 5, \ k=3, \ x=3 n=5, k=3, x=3, there is no three numbers which satisfies the condition, so the answer is “NO”. It can be shown that there are no three numbers whose sum is 3 3 3.

AC代码:

#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=9901;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;
 
ll n, k, x;
int main()
{
	int t ;
	cin >> t;
	while(t --){
		cin >> n >> k >> x;
		ll s1 = 0, s2 = 0;
		s1 = (1 + k) * k / 2; 
        s2 = (n - k + 1 + n) * k / 2;
		if(x >= s1 && x <= s2) puts("YES");
		else puts("NO");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值