#include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll const N = 5e5 + 9; ll const INF = 1e18 + 9; ll tab[N]; ll tab2[N]; ll pref[N]; bool odw[N]; ll oblicz(ll k, ll n) { if (odw[k] == 0) return false; ll sum = pref[k]; for (ll i = k + 1; i <= n; i++) { if (sum <= tab[i]) return false; sum += tab[i]; } return true; } ll binary_search(ll n) { ll p = 0, q = n + 1; while (p != q - 1) { ll pol = (p + q) / 2; if (oblicz(pol, n) == false) { p = pol; } else q = pol; } if (oblicz(p, n)) return p; return q; } void task(ll n) { tab[n + 1] = INF; sort(tab + 1, tab + n + 1); ll p = tab[1]; for (ll i = 1; i <= n; i++) { pref[i] = pref[i - 1] + tab[i]; odw[i] = odw[i - 1]; if (p != tab[i]) odw[i] = 1; } ll k = binary_search(n); ll sum = tab[k]; for (ll i = 1; i <= n; i++) { if (tab2[i] >= sum) cout << "T"; else cout << "N"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i = 1; i <= n; i++) { cin >> tab[i]; tab2[i] = tab[i]; } task(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 67 68 | #include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll const N = 5e5 + 9; ll const INF = 1e18 + 9; ll tab[N]; ll tab2[N]; ll pref[N]; bool odw[N]; ll oblicz(ll k, ll n) { if (odw[k] == 0) return false; ll sum = pref[k]; for (ll i = k + 1; i <= n; i++) { if (sum <= tab[i]) return false; sum += tab[i]; } return true; } ll binary_search(ll n) { ll p = 0, q = n + 1; while (p != q - 1) { ll pol = (p + q) / 2; if (oblicz(pol, n) == false) { p = pol; } else q = pol; } if (oblicz(p, n)) return p; return q; } void task(ll n) { tab[n + 1] = INF; sort(tab + 1, tab + n + 1); ll p = tab[1]; for (ll i = 1; i <= n; i++) { pref[i] = pref[i - 1] + tab[i]; odw[i] = odw[i - 1]; if (p != tab[i]) odw[i] = 1; } ll k = binary_search(n); ll sum = tab[k]; for (ll i = 1; i <= n; i++) { if (tab2[i] >= sum) cout << "T"; else cout << "N"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i = 1; i <= n; i++) { cin >> tab[i]; tab2[i] = tab[i]; } task(n); } |