#include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back using namespace std; typedef long long lld; lld ssm; vector<pair<lld, int> > v; vector<lld> sm; vector<char> s; int main() { int n; scanf("%d", &n); if(n == 1) { printf("T\n"); return 0; } for(int i = 0; i < n; ++i) { lld a; scanf("%lld", &a); v.pb(mp(a, i)); s.pb('N'); } sort(v.begin(), v.end()); if(v[0].ff < v.back().ff) { ssm = v[0].ff; sm.push_back(ssm); for(size_t i = 1; i < v.size(); ++i) { ssm += v[i].ff; if(v[i].ff == v[0].ff) { sm.pb(sm.back()); } else { sm.pb(ssm); } } int i = v.size()-2; s[v.back().ss] = 'T'; while(sm[i] > v[i+1].ff) { s[v[i].ss] = 'T'; --i; } } for(size_t i = 0; i < s.size(); ++i) { printf("%c", s[i]); } printf("\n"); }
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 | #include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back using namespace std; typedef long long lld; lld ssm; vector<pair<lld, int> > v; vector<lld> sm; vector<char> s; int main() { int n; scanf("%d", &n); if(n == 1) { printf("T\n"); return 0; } for(int i = 0; i < n; ++i) { lld a; scanf("%lld", &a); v.pb(mp(a, i)); s.pb('N'); } sort(v.begin(), v.end()); if(v[0].ff < v.back().ff) { ssm = v[0].ff; sm.push_back(ssm); for(size_t i = 1; i < v.size(); ++i) { ssm += v[i].ff; if(v[i].ff == v[0].ff) { sm.pb(sm.back()); } else { sm.pb(ssm); } } int i = v.size()-2; s[v.back().ss] = 'T'; while(sm[i] > v[i+1].ff) { s[v[i].ss] = 'T'; --i; } } for(size_t i = 0; i < s.size(); ++i) { printf("%c", s[i]); } printf("\n"); } |