#include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pp; vector<pp> ve; int n; bool check(int p) { // printf("check %d\n",p); ll siz=ve[p].ff; for(int i=0;i<n;++i) { // printf("%d %lld\n",i,siz); if(i==p) continue; if(siz<=ve[i].ff) return 0; siz+=ve[i].ff; } return 1; } int main() { scanf("%d",&n); vector<int> odp(n); for(int i=0;i<n;++i) { int v; scanf("%d",&v); ve.pb(mp(v,i)); } sort(ve.begin(),ve.end()); // for(auto I : ve) printf("%d %d ",I.ff,I.ss); // printf("\n"); int be=-1,en=n; while(be<en-1) { int mid=(be+en)/2; if(check(mid)) en=mid; else be=mid; } for(int i=en;i<n;++i) odp[ve[i].ss]=1; for(int i=0;i<n;++i) printf((odp[i] ? "T" : "N")); printf("\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 47 | #include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pp; vector<pp> ve; int n; bool check(int p) { // printf("check %d\n",p); ll siz=ve[p].ff; for(int i=0;i<n;++i) { // printf("%d %lld\n",i,siz); if(i==p) continue; if(siz<=ve[i].ff) return 0; siz+=ve[i].ff; } return 1; } int main() { scanf("%d",&n); vector<int> odp(n); for(int i=0;i<n;++i) { int v; scanf("%d",&v); ve.pb(mp(v,i)); } sort(ve.begin(),ve.end()); // for(auto I : ve) printf("%d %d ",I.ff,I.ss); // printf("\n"); int be=-1,en=n; while(be<en-1) { int mid=(be+en)/2; if(check(mid)) en=mid; else be=mid; } for(int i=en;i<n;++i) odp[ve[i].ss]=1; for(int i=0;i<n;++i) printf((odp[i] ? "T" : "N")); printf("\n"); } |