#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; struct ryba { int w, nr; }; bool por(ryba a, ryba b) { if (a.w < b.w) return true; if (a.w > b.w) return false; return a.nr < b.nr; } bool Ok(vector<ryba>& a, int k) { vector<int> r; for (int i = 0; i < a.size(); ++i) if (i != k) r.push_back(a[i].w); ll suma = a[k].w; int i = 0; while (i < r.size() && r[i] < suma) { suma += r[i]; ++i; } return i == r.size(); } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<ryba> a(n); for (int i = 0; i < n; ++i) { cin >> a[i].w; a[i].nr = i; } sort(a.begin(), a.end(), por); int l = 0, p = n - 1, s, r = -1; while (l <= p) { s = (l + p) / 2; if (Ok(a, s)) { r = s; p = s - 1; } else l = s + 1; } string odp(n, 'N'); if (r != -1) for (int i = r; i < n; ++i) odp[a[i].nr] = 'T'; cout << odp; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; struct ryba { int w, nr; }; bool por(ryba a, ryba b) { if (a.w < b.w) return true; if (a.w > b.w) return false; return a.nr < b.nr; } bool Ok(vector<ryba>& a, int k) { vector<int> r; for (int i = 0; i < a.size(); ++i) if (i != k) r.push_back(a[i].w); ll suma = a[k].w; int i = 0; while (i < r.size() && r[i] < suma) { suma += r[i]; ++i; } return i == r.size(); } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<ryba> a(n); for (int i = 0; i < n; ++i) { cin >> a[i].w; a[i].nr = i; } sort(a.begin(), a.end(), por); int l = 0, p = n - 1, s, r = -1; while (l <= p) { s = (l + p) / 2; if (Ok(a, s)) { r = s; p = s - 1; } else l = s + 1; } string odp(n, 'N'); if (r != -1) for (int i = r; i < n; ++i) odp[a[i].nr] = 'T'; cout << odp; return 0; } |