#include <bits/stdc++.h> using namespace std; constexpr int LIM = 5e5; pair<long long, int> a[LIM + 3]; long long p[LIM + 3]; bitset<LIM> res; int n; void printAns() { for(int i = 0; i < n; ++i) { printf("%c", res[i] ? 'T' : 'N'); } } bool comp(pair<long long, int> a, long long b) { return a.first > b; } int main() { long long ti; bool diff = false; scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%lld", &ti); a[i] = make_pair(ti, i); if(i >= 1 && a[i].first != a[i - 1].first) diff = true; } if(!diff) { printAns(); return 0; } sort(a, a + n, greater<pair<long long ,int> >()); res[a[0].second] = 1; int sad_index = n - 1; for(; sad_index >= 0; --sad_index) { if(a[sad_index].first != a[sad_index - 1].first) break; } for(int i = n - 1; i >= 0; --i) { p[i] = p[i + 1] + a[i + 1].first; } /* for(int i = 0; i <= n + 1; ++i) { cout << p[i] << " "; } cout << endl; */ for(int i = 1; i < sad_index; ++i) { if(a[i].first == a[i - 1].first) { res[a[i].second] = 1; } else if(p[i] + a[i].first > a[i - 1].first) { res[a[i].second] = 1; } else { break; } } printAns(); }
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 69 | #include <bits/stdc++.h> using namespace std; constexpr int LIM = 5e5; pair<long long, int> a[LIM + 3]; long long p[LIM + 3]; bitset<LIM> res; int n; void printAns() { for(int i = 0; i < n; ++i) { printf("%c", res[i] ? 'T' : 'N'); } } bool comp(pair<long long, int> a, long long b) { return a.first > b; } int main() { long long ti; bool diff = false; scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%lld", &ti); a[i] = make_pair(ti, i); if(i >= 1 && a[i].first != a[i - 1].first) diff = true; } if(!diff) { printAns(); return 0; } sort(a, a + n, greater<pair<long long ,int> >()); res[a[0].second] = 1; int sad_index = n - 1; for(; sad_index >= 0; --sad_index) { if(a[sad_index].first != a[sad_index - 1].first) break; } for(int i = n - 1; i >= 0; --i) { p[i] = p[i + 1] + a[i + 1].first; } /* for(int i = 0; i <= n + 1; ++i) { cout << p[i] << " "; } cout << endl; */ for(int i = 1; i < sad_index; ++i) { if(a[i].first == a[i - 1].first) { res[a[i].second] = 1; } else if(p[i] + a[i].first > a[i - 1].first) { res[a[i].second] = 1; } else { break; } } printAns(); } |