#include <bits/stdc++.h> using namespace std; int n, a, b, c; vector<pair<int, int> > v; bool dasie[500100]; bool check(int c) { long long curr_sum = v[c].first; for (int i=0; i<n; i++) { if (i == c) continue; if (v[i].first < curr_sum) { curr_sum += v[i].first; } else { return false; } } return true; } int main () { cin >> n; for (int i=0; i<n; i++) { cin >> a; v.push_back(make_pair(a, i)); } sort(v.begin(), v.end()); a = 1, b = n; while (a < b) { c = (a + b) / 2; if (check(c)) { b = c; } else { a = c + 1; } } for (int i=0; i<a; i++) { dasie[v[i].second] = false; } for (int i=a; i<n; i++) { dasie[v[i].second] = true; } for (int i=0; i<n; i++) { if (dasie[i]) cout << "T"; else cout << "N"; } cout << endl; }
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 | #include <bits/stdc++.h> using namespace std; int n, a, b, c; vector<pair<int, int> > v; bool dasie[500100]; bool check(int c) { long long curr_sum = v[c].first; for (int i=0; i<n; i++) { if (i == c) continue; if (v[i].first < curr_sum) { curr_sum += v[i].first; } else { return false; } } return true; } int main () { cin >> n; for (int i=0; i<n; i++) { cin >> a; v.push_back(make_pair(a, i)); } sort(v.begin(), v.end()); a = 1, b = n; while (a < b) { c = (a + b) / 2; if (check(c)) { b = c; } else { a = c + 1; } } for (int i=0; i<a; i++) { dasie[v[i].second] = false; } for (int i=a; i<n; i++) { dasie[v[i].second] = true; } for (int i=0; i<n; i++) { if (dasie[i]) cout << "T"; else cout << "N"; } cout << endl; } |