#include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <unordered_map> using namespace std; int main() { int n,a; vector<long long int> v, original; unordered_map<long long int, bool> map; scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&a); original.push_back(a); v.push_back(a); } sort(v.begin(),v.end()); vector<long long int> sum; sum.push_back(0); for (int i=0; i<n; i++) sum.push_back(sum[i]+v[i]); //for (int i=0; i<n; i++) // cout << sum[i] << " "; //cout << "\n"; map[v[n-1]] = true; bool notWay = false; for (int i=n-2; i>=0; i--) { if (notWay) map[v[i]] = false; if (map.find(v[i]) != map.end()) continue; if (v[i] + sum[i] > v[i+1]) map[v[i]] = true; else { map[v[i]] = false; notWay = true; } } if (v.size() > 1) map[v[0]] = false; for (int i =0; i<n; i++) if (map[original[i]]) printf("T"); else printf("N"); 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 59 | #include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <unordered_map> using namespace std; int main() { int n,a; vector<long long int> v, original; unordered_map<long long int, bool> map; scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&a); original.push_back(a); v.push_back(a); } sort(v.begin(),v.end()); vector<long long int> sum; sum.push_back(0); for (int i=0; i<n; i++) sum.push_back(sum[i]+v[i]); //for (int i=0; i<n; i++) // cout << sum[i] << " "; //cout << "\n"; map[v[n-1]] = true; bool notWay = false; for (int i=n-2; i>=0; i--) { if (notWay) map[v[i]] = false; if (map.find(v[i]) != map.end()) continue; if (v[i] + sum[i] > v[i+1]) map[v[i]] = true; else { map[v[i]] = false; notWay = true; } } if (v.size() > 1) map[v[0]] = false; for (int i =0; i<n; i++) if (map[original[i]]) printf("T"); else printf("N"); printf("\n"); } |