// _| _| // _| _| _| _| _|_| _|_|_| _|_|_| _| _| _|_| _|_| // _|_| _| _| _|_|_|_| _| _| _|_| _|_| _|_|_|_| _|_|_|_| // _| _| _| _| _| _| _| _|_| _| _| _| _| // _| _| _|_|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_| // _| _| // _|_| _| #include <iostream> #include <algorithm> using namespace std; // #define DEBUG #ifdef DEBUG #define dassert(x) assert(x); #define df(...) printf(__VA_ARGS__) #else #define dassert(x) #define df(...) #endif #define x first #define y second #define mp make_pair #define pb push_back #define ir(x, a, b) ((a) <= (x) && (x) <= (b)) #define vec vector #define sz(x) (ll)x.size() #define foru(i, n) for (int i = 0; (i) < (n); ++(i)) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef pair<ll, ll> pll; int read() { int n = 0; bool b = 0; char c = getchar(); for (; !ir(c, '0', '9'); c = getchar()) b = (c == '-'); for (; ir(c, '0', '9'); c = getchar()) n = 10*n + (c-'0'); if (b) return -n; return n; } const int N = 5e5+10; ll a[N], b[N]; int n; bool check(ll x) { ll s = b[x]; for (int i = 0; i < n; ++i) { if (i == x) continue; if (b[i] >= s) return 0; s += b[i]; } return 1; } int main() { df("debug mode\n"); #ifndef DEBUG ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif n = read(); foru (i, n) { b[i] = a[i] = read(); } sort(b, b+n); int l = 0, r = n; df("[%d, %d)\n", l, r); while (l < r-1) { int mid = (l+r)/2; if (check(mid)) { r = mid; } else { l = mid+1; } df("[%d, %d)\n", l, r); } if (!check(l)) { ++l; } bool exist = 1; df("l: %d\n", l); if (l >= n) { exist = 0; } foru (i, n) { if (a[i] >= b[l] && exist) { printf("T"); } else { printf("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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | // _| _| // _| _| _| _| _|_| _|_|_| _|_|_| _| _| _|_| _|_| // _|_| _| _| _|_|_|_| _| _| _|_| _|_| _|_|_|_| _|_|_|_| // _| _| _| _| _| _| _| _|_| _| _| _| _| // _| _| _|_|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_| // _| _| // _|_| _| #include <iostream> #include <algorithm> using namespace std; // #define DEBUG #ifdef DEBUG #define dassert(x) assert(x); #define df(...) printf(__VA_ARGS__) #else #define dassert(x) #define df(...) #endif #define x first #define y second #define mp make_pair #define pb push_back #define ir(x, a, b) ((a) <= (x) && (x) <= (b)) #define vec vector #define sz(x) (ll)x.size() #define foru(i, n) for (int i = 0; (i) < (n); ++(i)) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef pair<ll, ll> pll; int read() { int n = 0; bool b = 0; char c = getchar(); for (; !ir(c, '0', '9'); c = getchar()) b = (c == '-'); for (; ir(c, '0', '9'); c = getchar()) n = 10*n + (c-'0'); if (b) return -n; return n; } const int N = 5e5+10; ll a[N], b[N]; int n; bool check(ll x) { ll s = b[x]; for (int i = 0; i < n; ++i) { if (i == x) continue; if (b[i] >= s) return 0; s += b[i]; } return 1; } int main() { df("debug mode\n"); #ifndef DEBUG ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif n = read(); foru (i, n) { b[i] = a[i] = read(); } sort(b, b+n); int l = 0, r = n; df("[%d, %d)\n", l, r); while (l < r-1) { int mid = (l+r)/2; if (check(mid)) { r = mid; } else { l = mid+1; } df("[%d, %d)\n", l, r); } if (!check(l)) { ++l; } bool exist = 1; df("l: %d\n", l); if (l >= n) { exist = 0; } foru (i, n) { if (a[i] >= b[l] && exist) { printf("T"); } else { printf("N"); } } printf("\n"); return 0; } |