#include <bits/stdc++.h> using namespace std; static bool comparator1(pair <int,int> p1, pair <int,int> p2) { return p1.first < p2.first; } static bool comparator2(pair <int,int> p1, pair <int,int> p2) { return p1.second < p2.second; } int main() { int n; scanf("%d", &n); vector <pair<int,int>> v; v.resize(n); for(int i = 0; i < n; ++i) { int val; scanf("%d", &val); v[i] = make_pair(val, i); } sort(v.begin(), v.end(), comparator1); int l = 0, r = n-1; bool rpossible = true; int valueposs = v[r].first + 1; int mid; long long sum = v[r].first; for(int i = 0; i < n; ++i){ if(i == r) continue; if(sum <= v[i].first) { rpossible = false; break; } sum += v[i].first; } if(!rpossible){ while(n--) printf("N"); printf("\n"); return 0; } while(l + 1 < r) { mid = (l+r)/2; sum = v[mid].first; for(int i = 0; i < n; ++i){ if(i == mid) continue; if(sum <= v[i].first) { l = mid; break; } sum += v[i].first; } if(l != mid) r = mid; } bool lpossible = true; sum = v[l].first; for(int i = 0; i < n; ++i){ if(i == l) continue; if(sum <= v[i].first) { lpossible = false; break; } sum += v[i].first; } valueposs = v[r].first; if(lpossible) valueposs = v[l].first; sort(v.begin(), v.end(), comparator2); for(size_t i = 0; i != v.size(); ++i) { if(v[i].first >= valueposs) printf("T"); else printf("N"); } printf("\n"); 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | #include <bits/stdc++.h> using namespace std; static bool comparator1(pair <int,int> p1, pair <int,int> p2) { return p1.first < p2.first; } static bool comparator2(pair <int,int> p1, pair <int,int> p2) { return p1.second < p2.second; } int main() { int n; scanf("%d", &n); vector <pair<int,int>> v; v.resize(n); for(int i = 0; i < n; ++i) { int val; scanf("%d", &val); v[i] = make_pair(val, i); } sort(v.begin(), v.end(), comparator1); int l = 0, r = n-1; bool rpossible = true; int valueposs = v[r].first + 1; int mid; long long sum = v[r].first; for(int i = 0; i < n; ++i){ if(i == r) continue; if(sum <= v[i].first) { rpossible = false; break; } sum += v[i].first; } if(!rpossible){ while(n--) printf("N"); printf("\n"); return 0; } while(l + 1 < r) { mid = (l+r)/2; sum = v[mid].first; for(int i = 0; i < n; ++i){ if(i == mid) continue; if(sum <= v[i].first) { l = mid; break; } sum += v[i].first; } if(l != mid) r = mid; } bool lpossible = true; sum = v[l].first; for(int i = 0; i < n; ++i){ if(i == l) continue; if(sum <= v[i].first) { lpossible = false; break; } sum += v[i].first; } valueposs = v[r].first; if(lpossible) valueposs = v[l].first; sort(v.begin(), v.end(), comparator2); for(size_t i = 0; i != v.size(); ++i) { if(v[i].first >= valueposs) printf("T"); else printf("N"); } printf("\n"); return 0; } |