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 n and b b b coins of value 1 1 1. You always pay in exact change, so you want to know if there exist such x x x and y y y that if you take x ( 0 ≤ x ≤ a ) x (0≤x≤a) x(0xa) coins of value n n n and y ( 0 ≤ y ≤ b ) y (0≤y≤b) y(0yb) coins of value 1 1 1, then the total value of taken coins will be S S S.

You have to answer q 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) q(1q104) — the number of test cases. Then q q q test cases follow.

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

Output

For the i i i-th test case print the answer on it — YES(without quotes) if there exist such x x x and y y y that if you take x x x coins of value n n n and y y y coins of value 1 1 1, then the total value of taken coins will be S 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 xn+y1=S,找到最大的不大于 S S S x x x ,再判断如果 x n + b xn+b xn+b不小于 S S S 则有答案,否则无答案
时间复杂度: O ( n l o g n ) O(n log n) O(nlogn)

代码

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值