#include<bits/stdc++.h> using namespace std; const int R=5e5+6; using ll=long long; ll s[R]; vector<ll>sumy; int tab[R]; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n;cin>>n; sumy.push_back(0); for(int i=1;i<=n;i++) { int a;cin>>a; sumy.push_back(a); tab[i]=a; } sort(sumy.begin(),sumy.end()); for(int i=1;i<=n;i++)s[i]=sumy[i]+s[i-1]; int id=n+1; if(sumy[1]<sumy[n])id=n; int res=id; for(int i=id;i>0;i--) { if(s[i]>sumy[i+1]&&sumy[i]>sumy[1])res=i; else break; } if(res==n+1)res=INT_MAX; else res=sumy[res]; for(int i=1;i<=n;i++) { if(tab[i]>=res)cout<<"T"; else cout<<"N"; } 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 | #include<bits/stdc++.h> using namespace std; const int R=5e5+6; using ll=long long; ll s[R]; vector<ll>sumy; int tab[R]; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n;cin>>n; sumy.push_back(0); for(int i=1;i<=n;i++) { int a;cin>>a; sumy.push_back(a); tab[i]=a; } sort(sumy.begin(),sumy.end()); for(int i=1;i<=n;i++)s[i]=sumy[i]+s[i-1]; int id=n+1; if(sumy[1]<sumy[n])id=n; int res=id; for(int i=id;i>0;i--) { if(s[i]>sumy[i+1]&&sumy[i]>sumy[1])res=i; else break; } if(res==n+1)res=INT_MAX; else res=sumy[res]; for(int i=1;i<=n;i++) { if(tab[i]>=res)cout<<"T"; else cout<<"N"; } cout<<"\n"; } |