# A. Avoiding Zero

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], b[N], n;

void solve() {
cin >> n;
int s1 = 0, s2 = 0;// 负数和 正数和
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < 0) s1 += a[i];
else s2 += a[i];
}
sort(a + 1, a + 1 + n);
s1 = abs(s1);

if (s1 > s2) { // 负数多
for (int i = 1; i <= n; i++) {
b[i] = a[i];
}
} else {
for (int i = 1; i <= n; i++) {
b[i] = a[n - i + 1];
}
}
int sum = 0;
int f = 0;
for (int i = 1; i <= n; i++) {
sum += b[i];
if (!sum) {
f = 1;
break;
}
}
if (f) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
for (int i = 1; i <= n; i++) {
cout << b[i] << " \n"[i == n];
}
}
}

void Run() {
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
solve();
}
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

Run();

return 0;
}


# B. Chess Cheater · 贪心

. . . W L . . . L ...WL...L

L . . . L W . . . L...LW...

. . . W L . . . L W . . . ...WL...LW...

L . . . L L...L

#include <bits/stdc++.h>
using namespace std;
string s;
int n, m, k;

struct L {
int x, b;

bool operator<(const L o) const {
if (b == o.b) return x < o.x;
return b > o.b;
}
};

vector<L> v;

void solve() {
cin >> n >> k;
cin >> s;

s = " " + s;
v.clear();
int lastW = -1;
int res = 0;
for (int i = 1; i <= n; i++) {
if (s[i] == 'L') {
int cnt = 0, j = i;
while (j <= n && s[j] == 'L') j++, cnt++;
i = j - 1;

if (lastW == -1 && j == n + 1) {//左无 右无
v.push_back({cnt, -1});
} else if (lastW == -1 || j == n + 1) {// 无左 右有 || 有左 无右
v.push_back({cnt, 0});
} else  v.push_back({cnt, 1});

} else {
if (lastW == i - 1)  res += 2;
else res++;

lastW = i;
}
}

n = v.size();
sort(v.begin(), v.end());
int sum = 0;
for (int i = 0; i < n; i++) {
if (sum + v[i].x <= k) {
sum += v[i].x;
res += v[i].x * 2 + v[i].b;
} else {
res += (k - sum) * 2 + (v[i].b == -1 && k - sum > 0 ? -1 : 0);
break;
}
}
cout << res << endl;
}

void Run() {
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
solve();
}
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

Run();

return 0;
}


10-11 64
02-11 146
04-07 692