#include <bits/stdc++.h> typedef long long int lli; typedef std::pair<lli, int> par; #define st first #define nd second const int MAXN = 500005; std::vector<par> v; bool t[MAXN]; bool is_king(lli x, int id) { for (int i=v.size()-1; i>0; i--) { if (i == id) continue; if (v[i].st >= x) return false; x += v[i].st; } return true; } int main() { int n; scanf("%d", &n); for (int i=0; i<n; i++) { int a; scanf("%d", &a); v.push_back({a,i}); } v.push_back({0, -1}); v.push_back({1000*1000*1000+10, -1}); std::sort(v.begin(), v.end()); std::reverse(v.begin(), v.end()); int p = 0, k = n+2; while (k-p > 1) { int s = (p+k)/2; if (is_king(v[s].st, s)) p = s; else k = s; } lli limit = v[p].st; for (auto x : v) { if (x.nd == -1) continue; t[x.nd] = (x.st >= limit); } for (int i=0; i<n; i++) if (t[i]) 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> typedef long long int lli; typedef std::pair<lli, int> par; #define st first #define nd second const int MAXN = 500005; std::vector<par> v; bool t[MAXN]; bool is_king(lli x, int id) { for (int i=v.size()-1; i>0; i--) { if (i == id) continue; if (v[i].st >= x) return false; x += v[i].st; } return true; } int main() { int n; scanf("%d", &n); for (int i=0; i<n; i++) { int a; scanf("%d", &a); v.push_back({a,i}); } v.push_back({0, -1}); v.push_back({1000*1000*1000+10, -1}); std::sort(v.begin(), v.end()); std::reverse(v.begin(), v.end()); int p = 0, k = n+2; while (k-p > 1) { int s = (p+k)/2; if (is_king(v[s].st, s)) p = s; else k = s; } lli limit = v[p].st; for (auto x : v) { if (x.nd == -1) continue; t[x.nd] = (x.st >= limit); } for (int i=0; i<n; i++) if (t[i]) printf("T"); else printf("N"); } |