Payment Without Change

You have aa coins of value nn and bb coins of value 11. You always pay in exact change, so you want to know if there exist such xx and yy that if you take xx (0≤x≤a0≤x≤a) coins of value nn and yy (0≤y≤b0≤y≤b) coins of value 11, then the total value of taken coins will be SS.

You have to answer qq independent test cases.

 

 

Input

 

The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases. Then qq test cases follow.

The only line of the test case contains four integers aa, bb, nn and SS (1≤a,b,n,S≤1091≤a,b,n,S≤109) — the number of coins of value nn, the number of coins of value 11, the value nn and the required total value.

 

 

Output

 

For the ii-th test case print the answer on it — YES (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11, then the total value of taken coins will be SS, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will 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
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
long long a,b,n,s;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%164d %164d %164d %164d",&a,&b,&n,&s);
		if(s<n){
			if(b<s){
				printf("NO\n");
			}else{
				printf("YES\n");
			}
		}else if(s==n){
			printf("YES\n");
		}else{
			if(s%n==0 && a*n>=s){
				printf("YES\n");
			}else if(s%n==0 && a*n<s){
				s=s-(a*n);
				if(s>b){
					printf("NO\n");
				}else{
					printf("YES\n");
				}
			}else{
				int t=s/n;
				if(t<=a){
					int t1=s-t*n;
					if(t1<=b)
						printf("YES\n");
					else
						printf("NO\n");
				}else{
					int t1=s-a*n;
					if(t1<=b)
						printf("YES\n");
					else
						printf("NO\n");
				}
			}
		}
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值