#include<iostream>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
ll t[500010];
map<ll,ll>m;
map<ll,ll>::iterator it;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,x,maks=-1;
string s={};
cin>>n;
for(ll i=0;i<n;i++){
cin>>t[i];
maks=max(maks,t[i]);
m[t[i]]++;
}
m[0]=0;
ll sum=0;
for(it=m.begin();it!=m.end();it++){
sum+=it->second*it->first;
m[it->first]=sum;
}
for(int i=0;i<n;i++){
sum=t[i];
//cout<<sum<<' ';
it=m.lower_bound(sum);
it--;
sum+=it->second;
//cout<<sum<<' ';
if(sum>maks){
cout<<'T';
//cout<<'\n';
continue;
}
it=m.lower_bound(sum);
it--;
bool g=0;
while(it->second>sum){
sum=it->second;
//cout<<sum<<' ';
if(sum>maks){
cout<<'T';
g=1;
break;
}
it=m.lower_bound(sum);
it--;
}
if(g==0){
cout<<'N';
}
//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 | #include<iostream> #include<utility> #include<algorithm> #include<map> using namespace std; typedef long long ll; ll t[500010]; map<ll,ll>m; map<ll,ll>::iterator it; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,x,maks=-1; string s={}; cin>>n; for(ll i=0;i<n;i++){ cin>>t[i]; maks=max(maks,t[i]); m[t[i]]++; } m[0]=0; ll sum=0; for(it=m.begin();it!=m.end();it++){ sum+=it->second*it->first; m[it->first]=sum; } for(int i=0;i<n;i++){ sum=t[i]; //cout<<sum<<' '; it=m.lower_bound(sum); it--; sum+=it->second; //cout<<sum<<' '; if(sum>maks){ cout<<'T'; //cout<<'\n'; continue; } it=m.lower_bound(sum); it--; bool g=0; while(it->second>sum){ sum=it->second; //cout<<sum<<' '; if(sum>maks){ cout<<'T'; g=1; break; } it=m.lower_bound(sum); it--; } if(g==0){ cout<<'N'; } //cout<<'\n'; } return 0; } |
English