样例都过了,下面只过了前五个点。思路是一旦判断到能进行元素反应,那么一定yes。因为翻倍后一定仍然满足整除,所以可以无限翻倍。 如果没有能元素反应的,判断和是否大于k。如果大于输出yes反之no。
#include <iostream>
#include <vector>
using namespace std;
#define int long long
signed main() {
int T;
cin >> T;
while (T--) {
int n, k,fg=0;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
int product = a[i] * a[j];
if (product % 147 == 0 || product % 154 == 0) {
fg=1;
goto qwe;
}
}
}
qwe:
if(fg==1) cout << "Yes" << endl;
else{
long long total = 0;
for (int i = 0; i < n; ++i) {
total += a[i];
}
if (total >= k) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
return 0;
};