#include <bits/stdc++.h> #define ll long long int using namespace std; int n; ll suma=0; vector <pair <ll, ll> > a; bool sprawdz(int poz) { ll waga=a[poz].first; int lic=1; while(lic<=n) { if(lic!=poz) { if(a[lic].first>=waga) break; waga+=a[lic].first; } ++lic; } if(waga==suma) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; a.push_back({-1, -1}); for(int i=0; i<n; ++i) { ll x; cin>>x; suma+=x; a.push_back({x, i+1}); } sort(a.begin(), a.end()); int p=1, k=n, sr; ll w=-1; // w - najmniejszy sum ktory moze zostac krolem while(p<=k) { sr=(p+k)/2; if(sprawdz(sr)) { k=sr-1; w=(ll)sr; } else p=sr+1; } if(w==-1) { for(int i=0; i<n; ++i) cout<<"N"; } else { w=a[(int)w].first; for(int i=1; i<=n; ++i) swap(a[i].first, a[i].second); sort(a.begin(), a.end()); for(int i=1; i<=n; ++i) { if(a[i].second>=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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include <bits/stdc++.h> #define ll long long int using namespace std; int n; ll suma=0; vector <pair <ll, ll> > a; bool sprawdz(int poz) { ll waga=a[poz].first; int lic=1; while(lic<=n) { if(lic!=poz) { if(a[lic].first>=waga) break; waga+=a[lic].first; } ++lic; } if(waga==suma) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; a.push_back({-1, -1}); for(int i=0; i<n; ++i) { ll x; cin>>x; suma+=x; a.push_back({x, i+1}); } sort(a.begin(), a.end()); int p=1, k=n, sr; ll w=-1; // w - najmniejszy sum ktory moze zostac krolem while(p<=k) { sr=(p+k)/2; if(sprawdz(sr)) { k=sr-1; w=(ll)sr; } else p=sr+1; } if(w==-1) { for(int i=0; i<n; ++i) cout<<"N"; } else { w=a[(int)w].first; for(int i=1; i<=n; ++i) swap(a[i].first, a[i].second); sort(a.begin(), a.end()); for(int i=1; i<=n; ++i) { if(a[i].second>=w) cout<<"T"; else cout<<"N"; } } return 0; } |