A. Payment Without Change(Codeforces Round #598 (Div. 3))

A. Payment Without Change(Codeforces Round #598 (Div. 3))

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Description

You have a coins of value n n and b b coins of value 1 1 . You always pay in exact change, so you want to know if there exist such x x and y y that if you take x ( 0 x a ) x (0≤x≤a) coins of value n n and y ( 0 y b ) y (0≤y≤b) coins of value 1 1 , then the total value of taken coins will be S S .

You have to answer q q independent test cases.

Input

The first line of the input contains one integer q ( 1 q 1 0 4 ) q (1≤q≤10^4) — the number of test cases. Then q q test cases follow.

The only line of the test case contains four integers a , b , n a, b, n and S ( 1 a , b , n , S 1 0 9 ) S (1≤a,b,n,S≤10^9) — the number of coins of value n n , the number of coins of value 1 1 , the value n n and the required total value.

Output

For the i i -th test case print the answer on it — YES(without quotes) if there exist such x x and y y that if you take x x coins of value n n and y y coins of value 1 1 , then the total value of taken coins will be S S , and NOotherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yesand YESwill all be recognized as positive answer).

Example

input

4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18

output

YES
NO
NO
YES

题解

列出等式 x n + y 1 = S x*n+y*1=S ,找到最大的不大于 S S x x ,再判断如果 x n + b xn+b 不小于 S S 则有答案,否则无答案
时间复杂度: O ( n l o g n ) O(n log n)

代码

#include <iostream>
#include <algorithm>
#include <vector>
#define maxn 300005
#define _for(i, a) for(LL i = 0; i < (a); i++)
using namespace std;
typedef long long LL;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);

	LL n;
	cin >> n;
	_for(q, n) {
		LL a, b, n, S;
		cin >> a >> b >> n >> S;
		LL ans = min(S / n, a);
		if (S - ans * n <= b) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}
发布了163 篇原创文章 · 获赞 54 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_42856843/article/details/102907718