【CodeForces 1256A --- Payment Without Change 】

本文详细解析了CodeForces1256A问题——支付问题,探讨了如何使用一定数量的n值硬币和1值硬币组合达到特定总价值S的方法。通过输入不同案例,代码演示了如何判断是否可以找到合适的硬币组合来完成支付。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【CodeForces 1256A --- Payment Without Change 】


Description

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

You have to answer q independent test cases.

Input

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

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

Output

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

Sample Input

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

Sample Output

YES
NO
NO
YES

AC代码:

#include <iostream>
#include <algorithm>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

int main()
{
    SIS;
    int a,b,n,s,T;
    cin >> T;
    while(T--)
    {
        cin >> a >> b >> n >> s;
        s-=min(s/n,a)*n;
        if(s>b) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值