#include <bits/stdc++.h> using namespace std; typedef long long LL; int n; vector<pair<LL, int> > v; bool cmp(pair<LL, int>a, pair<LL, int>b){ return a.second < b.second; } bool test(int x){ LL sum = v[x].first; for(int i=0; i<n; i++){ if(i==x){ continue; } if(sum > v[i].first){ sum += v[i].first; }else{ return false; } } return true; } int main(){ ios_base::sync_with_stdio(false); cin>>n; for(int i=0; i<n; i++){ LL tmp; cin>>tmp; v.push_back(make_pair(tmp, i)); } if(n==1){ cout<<"T\n"; return 0; } sort(v.begin(), v.end()); v.push_back(make_pair(0L, 0)); int l = 0, p = n; while(l!=p){ int s = (l+p)/2; if(test(s)){ p=s; }else{ l=s+1; } } for(int i=0; i<n; i++){ if(i<l){ v[i].first=-1; }else{ v[i].first=1; } } v.pop_back(); sort(v.begin(), v.end(), cmp); for(int i=0; i<n; i++){ if(v[i].first == -1){ cout<<"N"; }else{ cout<<"T"; } } cout<<"\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 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int n; vector<pair<LL, int> > v; bool cmp(pair<LL, int>a, pair<LL, int>b){ return a.second < b.second; } bool test(int x){ LL sum = v[x].first; for(int i=0; i<n; i++){ if(i==x){ continue; } if(sum > v[i].first){ sum += v[i].first; }else{ return false; } } return true; } int main(){ ios_base::sync_with_stdio(false); cin>>n; for(int i=0; i<n; i++){ LL tmp; cin>>tmp; v.push_back(make_pair(tmp, i)); } if(n==1){ cout<<"T\n"; return 0; } sort(v.begin(), v.end()); v.push_back(make_pair(0L, 0)); int l = 0, p = n; while(l!=p){ int s = (l+p)/2; if(test(s)){ p=s; }else{ l=s+1; } } for(int i=0; i<n; i++){ if(i<l){ v[i].first=-1; }else{ v[i].first=1; } } v.pop_back(); sort(v.begin(), v.end(), cmp); for(int i=0; i<n; i++){ if(v[i].first == -1){ cout<<"N"; }else{ cout<<"T"; } } cout<<"\n"; return 0; } |