#include <bits/stdc++.h> #define ll long long using namespace std; vector <ll> t; vector < pair <ll,ll> > q,p; int main() { ll n,a,minimum; cin>>n; for(int i=1;i<=n;i++) { cin>>a; if(i==1) minimum=a; minimum=min(minimum,a); t.push_back(a); q.push_back(make_pair(a,i)); } sort(q.begin(),q.end()); for(int i=0;i<q.size();i++) { if(i==0) p.push_back(make_pair(q[i].first,q[i].first)); else { if(q[i].first==p[p.size()-1].second) p[p.size()-1].first+=q[i].first; else p.push_back(make_pair(p[p.size()-1].first+q[i].first,q[i].first)); } } ll pom=p[p.size()-1].second; //for(int i=p.size()-1;i>=0;i--) //cout<<p[i].first<<" "<<p[i].second<<"\n"; for(int i=p.size()-2;i>=0;i--) { if(p[i].first>p[i+1].second) { //cout<<p[i].first<<" "<<p[i].second<<" first second\n"; //cout<<p[i].first<<" "<<p[i+1].second<<"\n"; pom=p[i].second; } else break; } for(int i=0;i<t.size();i++) { if(t[i]>=pom && t[i]!=minimum) cout<<"T"; else 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 | #include <bits/stdc++.h> #define ll long long using namespace std; vector <ll> t; vector < pair <ll,ll> > q,p; int main() { ll n,a,minimum; cin>>n; for(int i=1;i<=n;i++) { cin>>a; if(i==1) minimum=a; minimum=min(minimum,a); t.push_back(a); q.push_back(make_pair(a,i)); } sort(q.begin(),q.end()); for(int i=0;i<q.size();i++) { if(i==0) p.push_back(make_pair(q[i].first,q[i].first)); else { if(q[i].first==p[p.size()-1].second) p[p.size()-1].first+=q[i].first; else p.push_back(make_pair(p[p.size()-1].first+q[i].first,q[i].first)); } } ll pom=p[p.size()-1].second; //for(int i=p.size()-1;i>=0;i--) //cout<<p[i].first<<" "<<p[i].second<<"\n"; for(int i=p.size()-2;i>=0;i--) { if(p[i].first>p[i+1].second) { //cout<<p[i].first<<" "<<p[i].second<<" first second\n"; //cout<<p[i].first<<" "<<p[i+1].second<<"\n"; pom=p[i].second; } else break; } for(int i=0;i<t.size();i++) { if(t[i]>=pom && t[i]!=minimum) cout<<"T"; else cout<<"N"; } return 0; } |