#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; if (n == 1) { cout << "T\n"; return 0; } vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> orig = a; sort(a.begin(), a.end()); vector<ll> sums(n); sums[0] = a.front(); for (int i = 1; i < n; ++i) sums[i] = a[i] + sums[i - 1]; if (a.back() == a.front()) { cout << string(n, 'N') << "\n"; return 0; } int minKing = a.back(); for (int i = n - 2; i > 0; --i) { if (a[i] > a.front() && sums[i] > a[i + 1]) minKing = a[i]; else break; } for (const auto& x : orig) putchar(x >= minKing ? 'T' : 'N'); putchar('\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 | #include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; if (n == 1) { cout << "T\n"; return 0; } vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> orig = a; sort(a.begin(), a.end()); vector<ll> sums(n); sums[0] = a.front(); for (int i = 1; i < n; ++i) sums[i] = a[i] + sums[i - 1]; if (a.back() == a.front()) { cout << string(n, 'N') << "\n"; return 0; } int minKing = a.back(); for (int i = n - 2; i > 0; --i) { if (a[i] > a.front() && sums[i] > a[i + 1]) minKing = a[i]; else break; } for (const auto& x : orig) putchar(x >= minKing ? 'T' : 'N'); putchar('\n'); return 0; } |