#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = b; a <= i; i--) #define cat(x) cerr << #x << " = " << x << '\n'; using ll = long long; using namespace std; const int N = 500500; int n, a[N], b[N]; bool solve(int id) { ll s = b[id]; rep(i, 1, n) { if (i != id) { if (b[i] < s) s += b[i]; else return false; } } return true; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; rep(i, 1, n) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + n + 1); int l = 1, r = n + 1; while (l < r) { int m = (l + r) / 2; if (solve(m)) r = m; else l = m + 1; } rep(i, 1, n) { cout << ((l <= n && b[l] <= a[i]) ? 'T' : 'N'); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = b; a <= i; i--) #define cat(x) cerr << #x << " = " << x << '\n'; using ll = long long; using namespace std; const int N = 500500; int n, a[N], b[N]; bool solve(int id) { ll s = b[id]; rep(i, 1, n) { if (i != id) { if (b[i] < s) s += b[i]; else return false; } } return true; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; rep(i, 1, n) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + n + 1); int l = 1, r = n + 1; while (l < r) { int m = (l + r) / 2; if (solve(m)) r = m; else l = m + 1; } rep(i, 1, n) { cout << ((l <= n && b[l] <= a[i]) ? 'T' : 'N'); } return 0; } |