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 and coins of value . You always pay in exact change, so you want to know if there exist such and that if you take coins of value and coins of value , then the total value of taken coins will be .
You have to answer independent test cases.
Input
The first line of the input contains one integer — the number of test cases. Then test cases follow.
The only line of the test case contains four integers and — the number of coins of value , the number of coins of value , the value and the required total value.
Output
For the
-th test case print the answer on it — YES
(without quotes) if there exist such
and
that if you take
coins of value
and
coins of value
, then the total value of taken coins will be
, 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 <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;
}