#include <bits/stdc++.h> using namespace std; bool chk(vector<pair<int, int>>& v, int x) { long long t = v[x].first; for (int i = 0; i < v.size(); i++) { if (i == x) continue; if ((long long)v[i].first >= t) return false; t += (long long)v[i].first; } return true; } int main() { int n; scanf("%d", &n); vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { scanf("%d", &v[i].first); v[i].second = i; } sort(v.begin(), v.end()); int p = 0; int q = n-1; while (p < q) { int m = (p+q)/2; if (chk(v, m)) q = m; else p = m+1; } int pp = chk(v, p) ? v[p].first : INT_MAX;; sort(v.begin(), v.end(), [](auto a, auto b) { return a.second < b.second; }); for (int i = 0; i < n; i++) { if (v[i].first >= pp) printf("T"); else printf("N"); } }
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> using namespace std; bool chk(vector<pair<int, int>>& v, int x) { long long t = v[x].first; for (int i = 0; i < v.size(); i++) { if (i == x) continue; if ((long long)v[i].first >= t) return false; t += (long long)v[i].first; } return true; } int main() { int n; scanf("%d", &n); vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { scanf("%d", &v[i].first); v[i].second = i; } sort(v.begin(), v.end()); int p = 0; int q = n-1; while (p < q) { int m = (p+q)/2; if (chk(v, m)) q = m; else p = m+1; } int pp = chk(v, p) ? v[p].first : INT_MAX;; sort(v.begin(), v.end(), [](auto a, auto b) { return a.second < b.second; }); for (int i = 0; i < n; i++) { if (v[i].first >= pp) printf("T"); else printf("N"); } } |