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(0≤x≤a) coins of value n n n and y ( 0 ≤ y ≤ b ) y (0≤y≤b) y(0≤y≤b) 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(1≤q≤104) — 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(1≤a,b,n,S≤109) — 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 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
题解
列出等式
x
∗
n
+
y
∗
1
=
S
x*n+y*1=S
x∗n+y∗1=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;
}