#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<pair<ll, int> > a(n);
vector<char> w(n, 'N');
for(int i=0; i<n; i++)
{
cin>>a[i].first;
a[i].second=i;
}
sort(a.begin(), a.end());
vector<ll> pref(n);
for(int i=1; i<n; i++)
{
if(a[i].first==a[i-1].first)
pref[i]=pref[i-1];
else {
int j=i-1;
while(a[j].first==a[i-1].first)
{
pref[i]+=a[j].first;
j--;
}
pref[i]+=pref[i-1];
}
}
for(int i=0; i<n; i++)
{
ll res=pref[i]+a[i].first;
ll res0=-1;
while(res<=a[n-1].first)
{
int c=i, b=n;
while(b-c>0)
{
int m=c+((b-c)/2);
if(a[m].first<res)
{
c=m+1;
} else {
b=m;
}
}
if(res0==res) { break; }
res0=res;
res=pref[c];
}
if(res>a[n-1].first)
w[a[i].second]='T';
}
for(auto &x : w)
cout<<x;
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<pair<ll, int> > a(n); vector<char> w(n, 'N'); for(int i=0; i<n; i++) { cin>>a[i].first; a[i].second=i; } sort(a.begin(), a.end()); vector<ll> pref(n); for(int i=1; i<n; i++) { if(a[i].first==a[i-1].first) pref[i]=pref[i-1]; else { int j=i-1; while(a[j].first==a[i-1].first) { pref[i]+=a[j].first; j--; } pref[i]+=pref[i-1]; } } for(int i=0; i<n; i++) { ll res=pref[i]+a[i].first; ll res0=-1; while(res<=a[n-1].first) { int c=i, b=n; while(b-c>0) { int m=c+((b-c)/2); if(a[m].first<res) { c=m+1; } else { b=m; } } if(res0==res) { break; } res0=res; res=pref[c]; } if(res>a[n-1].first) w[a[i].second]='T'; } for(auto &x : w) cout<<x; return 0; } |
English