#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; int main() { int n, a; cin >> n; vector<PII> mass(n); for (int i = 0; i < n; ++i) { cin >> a; mass[i] = make_pair(a, i); } sort(mass.begin(), mass.end()); int low = 0; int high = n; while (low < high) { int mid = (low + high) / 2; bool ok = true; LL sum = mass[mid].first; for (int i = 0; i < n; ++i) { if (i == mid) continue; if (mass[i].first < sum) { sum += mass[i].first; } else { ok = false; break; } } if (ok) high = mid; else low = mid + 1; } string res(n, 'T'); for (int i = 0; i < high; ++i) { res[mass[i].second] = 'N'; } cout << res << endl; 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 | #include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; int main() { int n, a; cin >> n; vector<PII> mass(n); for (int i = 0; i < n; ++i) { cin >> a; mass[i] = make_pair(a, i); } sort(mass.begin(), mass.end()); int low = 0; int high = n; while (low < high) { int mid = (low + high) / 2; bool ok = true; LL sum = mass[mid].first; for (int i = 0; i < n; ++i) { if (i == mid) continue; if (mass[i].first < sum) { sum += mass[i].first; } else { ok = false; break; } } if (ok) high = mid; else low = mid + 1; } string res(n, 'T'); for (int i = 0; i < high; ++i) { res[mass[i].second] = 'N'; } cout << res << endl; return 0; } |