#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<int>v;
int n;
cin>>n;
bool same=true;
for(int i=0;i<n;i++){
int x;
cin>>x;
v.push_back(x);
if(i!=0&&v[i]!=v[i-1]){
same=false;
}
}
if(same){
//cout<<"xd";
for(int i=0;i<n;i++){
cout<<'N';
}
return 0;
}
vector<int>org=v;
sort(v.begin(),v.end());
//if()
int l=0;
int r=n-1;
while(l<r){
int m=(l+r)/2;
//cout<<m<<" ";
long long sum=v[m];
bool ok = true;
bool skipped=false;
for(int i=0;i<n;i++){
if(i==m){
continue;
}
if(v[i]>=sum){
ok=false;
break;
}
sum+=v[i];
}
if(!ok){
l=m+1;
}
else{
r=m;
}
}
//l=1000000001-l;
l= v[l];
for(int i=0;i<n;i++){
if(org[i]>=l){
cout<<'T';
}
else{
cout<<'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 60 61 62 63 | #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int>v; int n; cin>>n; bool same=true; for(int i=0;i<n;i++){ int x; cin>>x; v.push_back(x); if(i!=0&&v[i]!=v[i-1]){ same=false; } } if(same){ //cout<<"xd"; for(int i=0;i<n;i++){ cout<<'N'; } return 0; } vector<int>org=v; sort(v.begin(),v.end()); //if() int l=0; int r=n-1; while(l<r){ int m=(l+r)/2; //cout<<m<<" "; long long sum=v[m]; bool ok = true; bool skipped=false; for(int i=0;i<n;i++){ if(i==m){ continue; } if(v[i]>=sum){ ok=false; break; } sum+=v[i]; } if(!ok){ l=m+1; } else{ r=m; } } //l=1000000001-l; l= v[l]; for(int i=0;i<n;i++){ if(org[i]>=l){ cout<<'T'; } else{ cout<<'N'; } } } |
English