#include <bits/stdc++.h>
using namespace std;
const int mx=5e5+5;
int n,w,l,p,sr;
pair<long long,int>t[mx];
char krol[mx];
int dziala(int poz){
long long suma=t[poz].first;
for(int i=0;i<n;++i){
if(i==poz)continue;
if(suma>t[i].first){
suma+=t[i].first;
}
else{
return 0;
}
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;++i){
cin>>t[i].first;
t[i].second=i;
}
sort(t,t+n);
w=n;//minimalny indeks dla ktorego dziala
l=0;
p=n-1;
while(l<=p){
sr=(l+p)/2;
if(dziala(sr)==1){
w=sr;
p=sr-1;
}
else{
l=sr+1;
}
}
for(int i=0;i<w;++i){
krol[t[i].second]='N';
}
for(int i=w;i<n;++i){
krol[t[i].second]='T';
}
for(int i=0;i<n;++i){
cout<<krol[i];
}
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 | #include <bits/stdc++.h> using namespace std; const int mx=5e5+5; int n,w,l,p,sr; pair<long long,int>t[mx]; char krol[mx]; int dziala(int poz){ long long suma=t[poz].first; for(int i=0;i<n;++i){ if(i==poz)continue; if(suma>t[i].first){ suma+=t[i].first; } else{ return 0; } } return 1; } int main(){ ios::sync_with_stdio(false); cin>>n; for(int i=0;i<n;++i){ cin>>t[i].first; t[i].second=i; } sort(t,t+n); w=n;//minimalny indeks dla ktorego dziala l=0; p=n-1; while(l<=p){ sr=(l+p)/2; if(dziala(sr)==1){ w=sr; p=sr-1; } else{ l=sr+1; } } for(int i=0;i<w;++i){ krol[t[i].second]='N'; } for(int i=w;i<n;++i){ krol[t[i].second]='T'; } for(int i=0;i<n;++i){ cout<<krol[i]; } return 0; } |
English