#include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vll vector<ll> #define vvll vector<vll> #define vvvll vector<vvll> #define vvvvll vector<vvvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; void solve() { int n; cin >> n; vpll a(n + 1, {0, 0}); ll smallest = 1e10; repi(i, 1, n) { cin >> a[i].fi; a[i].se = i; smallest = min(smallest, a[i].fi); } sort(a.begin(), a.end()); vll pref(n + 1, 0); map<ll, ll> cnt; repi(i, 1, n) { cnt[a[i].fi]++; pref[i] = pref[i - 1] + a[i].fi; } vb keng(n + 1, false); for (int i = n; i >= 1; i--) { ll nxt = i < n ? a[i + 1].fi : 0; if (pref[i - 1] + a[i].fi <= nxt) { break; } if (a[i].fi == smallest) break; keng[a[i].se] = true; } str ans; repi(i, 1, n) { if (keng[i]) ans.push_back('T'); else ans.push_back('N'); } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); bool _multipleTestCases = false; if (_multipleTestCases) { ll t; cin >> t; while (t--) solve(); } else { solve(); } 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vll vector<ll> #define vvll vector<vll> #define vvvll vector<vvll> #define vvvvll vector<vvvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; void solve() { int n; cin >> n; vpll a(n + 1, {0, 0}); ll smallest = 1e10; repi(i, 1, n) { cin >> a[i].fi; a[i].se = i; smallest = min(smallest, a[i].fi); } sort(a.begin(), a.end()); vll pref(n + 1, 0); map<ll, ll> cnt; repi(i, 1, n) { cnt[a[i].fi]++; pref[i] = pref[i - 1] + a[i].fi; } vb keng(n + 1, false); for (int i = n; i >= 1; i--) { ll nxt = i < n ? a[i + 1].fi : 0; if (pref[i - 1] + a[i].fi <= nxt) { break; } if (a[i].fi == smallest) break; keng[a[i].se] = true; } str ans; repi(i, 1, n) { if (keng[i]) ans.push_back('T'); else ans.push_back('N'); } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); bool _multipleTestCases = false; if (_multipleTestCases) { ll t; cin >> t; while (t--) solve(); } else { solve(); } return 0; } |