#include <bits/stdc++.h> using namespace std; long long int n,a,l,f,mid,pom,weight,br; vector<long long int>t; vector<long long int>t1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=0; i<n; i++) { cin>>a; t1.push_back(a); t.push_back(a); } sort(t.begin(), t.end()); f=0; l=n-1; mid=f+l; mid/=2; pom=n+1; while(f<=l) { weight=t[mid]; br=0; for(int j=0; j<n; j++) { if(j!=mid) { if(t[j]<weight) { weight+=t[j]; } else br=1; } } if(br==1) { f=mid+1; } else { l=mid-1; pom=min(mid,pom); //cout<<"słoik spermy\n"; } mid=f+l; mid/=2; } if(pom==n+1) { pom=n; t.push_back(21372137213769); } for(int i=0; i<n; i++) { if(t1[i]>=t[pom]) { cout<<"T"; } else { 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <bits/stdc++.h> using namespace std; long long int n,a,l,f,mid,pom,weight,br; vector<long long int>t; vector<long long int>t1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=0; i<n; i++) { cin>>a; t1.push_back(a); t.push_back(a); } sort(t.begin(), t.end()); f=0; l=n-1; mid=f+l; mid/=2; pom=n+1; while(f<=l) { weight=t[mid]; br=0; for(int j=0; j<n; j++) { if(j!=mid) { if(t[j]<weight) { weight+=t[j]; } else br=1; } } if(br==1) { f=mid+1; } else { l=mid-1; pom=min(mid,pom); //cout<<"słoik spermy\n"; } mid=f+l; mid/=2; } if(pom==n+1) { pom=n; t.push_back(21372137213769); } for(int i=0; i<n; i++) { if(t1[i]>=t[pom]) { cout<<"T"; } else { cout<<"N"; } } } |