A.Phoenix and Gold
题目传送门:
题面:
代码:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int T;
int n, x;
int a[200];
int main() {
cin >> T;
while (T--) {
cin >> n >> x;
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum == x) {
cout << "NO" << '\n';
//如果总和一定是x,那么一定会达到。
continue;
}
//否则一定可以避免。
sort(a + 1, a + 1 + n);
sum = 0;
for (int i = 1; i <= n; i++) {
sum += a[i];
if (sum == x) {
sum -= a[i];
swap(a[i], a[i + 1]);
sum += a[i];
}
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
}
五一假期
在这摸鱼!