#include<bits/stdc++.h> using namespace std; long long n,tab[500007],cot[500007],sum; bool a(int a,int b) { return a>b; } bool kingsum(long long summ,int ws) { for(long long i=n-1;i>=0;i--) { if(i!=ws) { if(tab[i]<summ) summ+=tab[i]; else return 0; } //else return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=0;i<n;i++) { cin >> tab[i]; cot[i]=tab[i]; } sort(tab,tab+n,a); bool cz=0; if(tab[0]==tab[n-1]) cz=1; int l=0; int p=n-1; int w; //cout << kingsum(tab[2],2) << "\n"; while(l<p) { w=(l+p)/2; //cout << w << "\n"; if(kingsum(tab[w],w)) l=w+1; else p=w; } if(w==p) w--; if(w==-1) {w=0;tab[0]++;} /* cout << "\n\n" << w << "\n"; cout << cot[1] << " " << cot[2] << " " << cot[3] << "\n"; cout << tab[w] << "\n"; cout << tab[1] << " " << tab[2] << " " << tab[3] << "\n"; */ for(int i=0;i<n;i++) { if(cot[i]>=tab[w]) 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 57 58 59 60 61 62 63 | #include<bits/stdc++.h> using namespace std; long long n,tab[500007],cot[500007],sum; bool a(int a,int b) { return a>b; } bool kingsum(long long summ,int ws) { for(long long i=n-1;i>=0;i--) { if(i!=ws) { if(tab[i]<summ) summ+=tab[i]; else return 0; } //else return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=0;i<n;i++) { cin >> tab[i]; cot[i]=tab[i]; } sort(tab,tab+n,a); bool cz=0; if(tab[0]==tab[n-1]) cz=1; int l=0; int p=n-1; int w; //cout << kingsum(tab[2],2) << "\n"; while(l<p) { w=(l+p)/2; //cout << w << "\n"; if(kingsum(tab[w],w)) l=w+1; else p=w; } if(w==p) w--; if(w==-1) {w=0;tab[0]++;} /* cout << "\n\n" << w << "\n"; cout << cot[1] << " " << cot[2] << " " << cot[3] << "\n"; cout << tab[w] << "\n"; cout << tab[1] << " " << tab[2] << " " << tab[3] << "\n"; */ for(int i=0;i<n;i++) { if(cot[i]>=tab[w]) cout << "T"; else cout << "N"; } return(0); } |