#include<iostream> #include<vector> #include<utility> #include<algorithm> #define LL long long int using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); vector <pair <LL,LL> > tab; vector<LL> suma, wynik; pair <LL,LL> el; LL n, waga; cin >>n; tab.resize(n); suma.resize(n); wynik.resize(n); for (int i=0;i<n;i++){ cin >>waga; el = make_pair(waga,i); tab[i] = el; } sort(tab.begin(),tab.end()); suma[0] = tab[0].first; for (int i = 1;i<n;i++){ suma[i] = suma[i-1] + tab[i].first; } wynik[tab[0].second] =0; wynik[tab[n-1].second] = 1; for (int i = n -1;i > 0;i-- ){ if (tab[i].first < suma[i-1]){ int nr = tab[i-1].second; wynik[nr] = 1; } else break; } for (int i=1;i<n;i++){ if (tab[0].first == tab[i].first){ int nr = tab[i].second; wynik[nr] = 0; } else break; } for (int i=0;i<n;i++) if (wynik[i] == 1) cout <<"T"; else cout <<"N"; cout <<endl; 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 | #include<iostream> #include<vector> #include<utility> #include<algorithm> #define LL long long int using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); vector <pair <LL,LL> > tab; vector<LL> suma, wynik; pair <LL,LL> el; LL n, waga; cin >>n; tab.resize(n); suma.resize(n); wynik.resize(n); for (int i=0;i<n;i++){ cin >>waga; el = make_pair(waga,i); tab[i] = el; } sort(tab.begin(),tab.end()); suma[0] = tab[0].first; for (int i = 1;i<n;i++){ suma[i] = suma[i-1] + tab[i].first; } wynik[tab[0].second] =0; wynik[tab[n-1].second] = 1; for (int i = n -1;i > 0;i-- ){ if (tab[i].first < suma[i-1]){ int nr = tab[i-1].second; wynik[nr] = 1; } else break; } for (int i=1;i<n;i++){ if (tab[0].first == tab[i].first){ int nr = tab[i].second; wynik[nr] = 0; } else break; } for (int i=0;i<n;i++) if (wynik[i] == 1) cout <<"T"; else cout <<"N"; cout <<endl; return 0; } |