#include <iostream> #include <vector> #include <algorithm> using namespace std; struct sum_t { int size; int index; bool operator<(const sum_t& t) const { return size<t.size; } }; /* 6 2 7 1 8 2 8 x */ int main() { int n; cin >> n; vector<sum_t> a(n); for(int i=0;i<n;++i) { cin >> a[i].size; a[i].index=i; } sort(a.begin(), a.end()); if(n==1) { cout << "T"; return 0; } string result(n, 'N'); long long int sum = a[0].size; int i=1; while(i<n&&a[0].size==a[i].size) { sum+=a[i].size; ++i; } int firstKing=i; while(i<n) { if(sum<=a[i].size) firstKing=i; sum+=a[i].size; ++i; } for(int i=firstKing;i<n;++i) result[a[i].index] = 'T'; cout << result; 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 <iostream> #include <vector> #include <algorithm> using namespace std; struct sum_t { int size; int index; bool operator<(const sum_t& t) const { return size<t.size; } }; /* 6 2 7 1 8 2 8 x */ int main() { int n; cin >> n; vector<sum_t> a(n); for(int i=0;i<n;++i) { cin >> a[i].size; a[i].index=i; } sort(a.begin(), a.end()); if(n==1) { cout << "T"; return 0; } string result(n, 'N'); long long int sum = a[0].size; int i=1; while(i<n&&a[0].size==a[i].size) { sum+=a[i].size; ++i; } int firstKing=i; while(i<n) { if(sum<=a[i].size) firstKing=i; sum+=a[i].size; ++i; } for(int i=firstKing;i<n;++i) result[a[i].index] = 'T'; cout << result; return 0; } |