#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[500010], b[500010]; bool ok(int x) { ll s=(ll)a[x]; for(int i=1; i<=n; ++i) { if(i==x)continue; if(s<=a[i])return false; s+=a[i]; } return true; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin>>n; for(int i=1; i<=n; ++i) { cin>>a[i]; b[i]=a[i]; } sort(a+1, a+n+1); int p=1, q=n; while(p<q) { int mid=(p+q)/2; if(!ok(mid))p=mid+1; else q=mid; } if(p==n)p=(ok(n)?n:n+1); a[n+1]=(ll)INT_MAX; for(int i=1; i<=n; ++i) { if(b[i]>=a[p])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 46 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[500010], b[500010]; bool ok(int x) { ll s=(ll)a[x]; for(int i=1; i<=n; ++i) { if(i==x)continue; if(s<=a[i])return false; s+=a[i]; } return true; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin>>n; for(int i=1; i<=n; ++i) { cin>>a[i]; b[i]=a[i]; } sort(a+1, a+n+1); int p=1, q=n; while(p<q) { int mid=(p+q)/2; if(!ok(mid))p=mid+1; else q=mid; } if(p==n)p=(ok(n)?n:n+1); a[n+1]=(ll)INT_MAX; for(int i=1; i<=n; ++i) { if(b[i]>=a[p])cout<<"T"; else cout<<"N"; } cout<<"\n"; } |