#include <bits/stdc++.h> using namespace std; int n,i,l,r,mid; long long cur; pair<int,int> a[500500]; char res[500500]; int main() { scanf("%d",&n); for (i=0; i<n; i++) { scanf("%d",&a[i].first); a[i].second=i; } sort(a,a+n); l=0; r=n-1; while (l<r) { mid=(l+r)/2+1; cur=a[mid].first; for (i=0; i<n; i++) if (i!=mid) { if (cur>a[i].first) cur+=a[i].first; else break; } if (i<n) l=mid; else r=mid-1; } for (i=0; i<=r; i++) res[a[i].second]='N'; for (; i<n; i++) res[a[i].second]='T'; puts(res); 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 | #include <bits/stdc++.h> using namespace std; int n,i,l,r,mid; long long cur; pair<int,int> a[500500]; char res[500500]; int main() { scanf("%d",&n); for (i=0; i<n; i++) { scanf("%d",&a[i].first); a[i].second=i; } sort(a,a+n); l=0; r=n-1; while (l<r) { mid=(l+r)/2+1; cur=a[mid].first; for (i=0; i<n; i++) if (i!=mid) { if (cur>a[i].first) cur+=a[i].first; else break; } if (i<n) l=mid; else r=mid-1; } for (i=0; i<=r; i++) res[a[i].second]='N'; for (; i<n; i++) res[a[i].second]='T'; puts(res); return 0; } |