#include<bits/stdc++.h> using namespace std; long long tab[500009], vals[500007]; int n; bool check (long long a) { long long s=a, f=0, b=1; for(int i=1; i<=n; i++) { if(vals[i]<s) { if(vals[i] == a && f == 0) f=1; else s += vals[i]; } else if (vals[i] == a && f == 0) f=1; else b=0; } if(b == 1) return true; else return false; } int main() { ios_base::sync_with_stdio(0); cin>>n; for(int i=1; i<=n; i++) { cin>>tab[i]; vals[i] = tab[i]; } sort(vals+1, vals+1+n); long long res = 1000000001, poc = 1, kon = n; while(poc<=kon) { long long sr = (poc+kon)/2; if (check(vals[sr]) == true) { res = min(res, vals[sr]); kon = sr - 1; } else poc = sr + 1; } for(int i=1; i<=n; i++) if(tab[i] >= res) 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 | #include<bits/stdc++.h> using namespace std; long long tab[500009], vals[500007]; int n; bool check (long long a) { long long s=a, f=0, b=1; for(int i=1; i<=n; i++) { if(vals[i]<s) { if(vals[i] == a && f == 0) f=1; else s += vals[i]; } else if (vals[i] == a && f == 0) f=1; else b=0; } if(b == 1) return true; else return false; } int main() { ios_base::sync_with_stdio(0); cin>>n; for(int i=1; i<=n; i++) { cin>>tab[i]; vals[i] = tab[i]; } sort(vals+1, vals+1+n); long long res = 1000000001, poc = 1, kon = n; while(poc<=kon) { long long sr = (poc+kon)/2; if (check(vals[sr]) == true) { res = min(res, vals[sr]); kon = sr - 1; } else poc = sr + 1; } for(int i=1; i<=n; i++) if(tab[i] >= res) cout<<"T"; else cout<<"N"; return 0; } |