#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; #define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b)) using ll = long long; const int INF = 1e9+10; int main() { int n; scanf("%d", &n); assert(n >= 2); vector<int> org_a(n); for (int i = 0; i < n; ++i) { scanf("%d", &org_a[i]); } vector<ll> a(n); for (int i = 0; i < n; ++i) { a[i] = org_a[i]; } sort(a.begin(), a.end()); int lo = INF; vector<ll> pref(n); pref[0] = a[0]; for (int i = 1; i < n; ++i) { pref[i] = pref[i-1] + a[i]; } for (int i = 0; i < n; ++i) { // cout << "--- " << i << endl; if (i > 0 && a[i] == a[i-1]) continue; ll cur = pref[i]; int j = i; while (true) { // cout << "\t" << cur << endl; auto it = lower_bound(a.begin(), a.end(), cur); if (it == a.end()) { lo = a[i]; break; } else { if (it == a.begin()) { // nothing new can be eaten later break; } --it; int new_j = distance(a.begin(), it); // cout << "\ti=" << i << " " << "j=" << new_j << endl; if (j == new_j) { // nothing new can be eaten later break; } else { cur = pref[new_j]; j = new_j; } } } if (lo < INF) break; } // printf("%d\n", lo); for (int i = 0; i < n; ++i) { printf("%c", org_a[i] >= lo ? 'T' : 'N'); } printf("\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 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 | #include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> #include <ctime> #include <cassert> using namespace std; #define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b)) using ll = long long; const int INF = 1e9+10; int main() { int n; scanf("%d", &n); assert(n >= 2); vector<int> org_a(n); for (int i = 0; i < n; ++i) { scanf("%d", &org_a[i]); } vector<ll> a(n); for (int i = 0; i < n; ++i) { a[i] = org_a[i]; } sort(a.begin(), a.end()); int lo = INF; vector<ll> pref(n); pref[0] = a[0]; for (int i = 1; i < n; ++i) { pref[i] = pref[i-1] + a[i]; } for (int i = 0; i < n; ++i) { // cout << "--- " << i << endl; if (i > 0 && a[i] == a[i-1]) continue; ll cur = pref[i]; int j = i; while (true) { // cout << "\t" << cur << endl; auto it = lower_bound(a.begin(), a.end(), cur); if (it == a.end()) { lo = a[i]; break; } else { if (it == a.begin()) { // nothing new can be eaten later break; } --it; int new_j = distance(a.begin(), it); // cout << "\ti=" << i << " " << "j=" << new_j << endl; if (j == new_j) { // nothing new can be eaten later break; } else { cur = pref[new_j]; j = new_j; } } } if (lo < INF) break; } // printf("%d\n", lo); for (int i = 0; i < n; ++i) { printf("%c", org_a[i] >= lo ? 'T' : 'N'); } printf("\n"); return 0; } |