#include <bits/stdc++.h> using namespace std; #define ff first #define ss second int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector <pair <int, int> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].ff; v[i].ss = i; } sort(v.begin(), v.end()); vector <long long> pref(n); vector <bool> pom(n), res(n); for (int i = 0; i < n-1; i++) { pref[i] += (long long)v[i].ff; if (i) { pref[i] += pref[i-1]; if (pref[i] > v[i+1].ff) pom[i] = true; } } pom[n-1] = true; for (int i = 0; i < n; i++) { if (v[i].ff == v[0].ff) pom[i] = false; else break; } for (int i = n - 1; i >= 0; i--) { if (!pom[i]) break; res[v[i].ss] = true; } for (int i = 0; i < n; i++) { if (res[i]) cout << 'T'; else cout << 'N'; } cout << "\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 | #include <bits/stdc++.h> using namespace std; #define ff first #define ss second int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector <pair <int, int> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].ff; v[i].ss = i; } sort(v.begin(), v.end()); vector <long long> pref(n); vector <bool> pom(n), res(n); for (int i = 0; i < n-1; i++) { pref[i] += (long long)v[i].ff; if (i) { pref[i] += pref[i-1]; if (pref[i] > v[i+1].ff) pom[i] = true; } } pom[n-1] = true; for (int i = 0; i < n; i++) { if (v[i].ff == v[0].ff) pom[i] = false; else break; } for (int i = n - 1; i >= 0; i--) { if (!pom[i]) break; res[v[i].ss] = true; } for (int i = 0; i < n; i++) { if (res[i]) cout << 'T'; else cout << 'N'; } cout << "\n"; return 0; } |