#include <bits/stdc++.h> using namespace std; vector <pair <int, int> > L; int n; bool czy_krol (pair <int, int> A, bool val) { long long s = A.first; for (int i = 0; i < n; i++) { if (L[i].second != A.second) { if (s <= L[i].first) return true; s += L[i].first; } } return false; } int main() { cin >> n; L.resize(n); char J[n]; for (int i = 0; i < n; i++) { int a; cin >> a; L[i] = {a, i}; } sort (L.begin(), L.end()); auto it = lower_bound(L.begin(), L.end(), true, czy_krol); for (int i = 0; i < n; i++) { if (i < (it - L.begin())) J[ L[i].second ] = 'N'; else J [ L[i].second ] = 'T'; } for (int i = 0; i < n; i++) cout << J[i]; 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 | #include <bits/stdc++.h> using namespace std; vector <pair <int, int> > L; int n; bool czy_krol (pair <int, int> A, bool val) { long long s = A.first; for (int i = 0; i < n; i++) { if (L[i].second != A.second) { if (s <= L[i].first) return true; s += L[i].first; } } return false; } int main() { cin >> n; L.resize(n); char J[n]; for (int i = 0; i < n; i++) { int a; cin >> a; L[i] = {a, i}; } sort (L.begin(), L.end()); auto it = lower_bound(L.begin(), L.end(), true, czy_krol); for (int i = 0; i < n; i++) { if (i < (it - L.begin())) J[ L[i].second ] = 'N'; else J [ L[i].second ] = 'T'; } for (int i = 0; i < n; i++) cout << J[i]; return 0; } |