#include<bits/stdc++.h> using namespace std; #define ll long long pair<ll, int> tab[500005]; int cmp(pair<int, int>a, pair<int, int>b){ if(a.first==b.first){ return a.second<b.second; } return a.first<b.first; } bool w[500005]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ ll a; cin>>a; tab[i].first=a; tab[i].second=i; } sort(tab, tab+n, cmp); ll z=0; ll x=0; int maks_poz=-1; for(int i=0;i<n;i++){ //cout<<z<<" "; if(tab[i-1].first==z&&tab[i].first==z){ x+=tab[i].first; maks_poz=i; //cout<<" 1 :"; continue; } if(tab[i].first>=z){ z+=tab[i].first; z+=x; x=0; maks_poz=i-1; //cout<<" 2 :"; continue; } if(tab[i].first<z){ z+=tab[i].first; z+=x; x=0; //cout<<" 3 :"; } } //cout<<z; //cout<<maks_poz; for(int i=0;i<=maks_poz;i++){ w[tab[i].second]=1; } for(int i=0;i<n;i++){ if(w[i]==1){ cout<<"N"; } else{ cout<<"T"; } } 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 | #include<bits/stdc++.h> using namespace std; #define ll long long pair<ll, int> tab[500005]; int cmp(pair<int, int>a, pair<int, int>b){ if(a.first==b.first){ return a.second<b.second; } return a.first<b.first; } bool w[500005]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ ll a; cin>>a; tab[i].first=a; tab[i].second=i; } sort(tab, tab+n, cmp); ll z=0; ll x=0; int maks_poz=-1; for(int i=0;i<n;i++){ //cout<<z<<" "; if(tab[i-1].first==z&&tab[i].first==z){ x+=tab[i].first; maks_poz=i; //cout<<" 1 :"; continue; } if(tab[i].first>=z){ z+=tab[i].first; z+=x; x=0; maks_poz=i-1; //cout<<" 2 :"; continue; } if(tab[i].first<z){ z+=tab[i].first; z+=x; x=0; //cout<<" 3 :"; } } //cout<<z; //cout<<maks_poz; for(int i=0;i<=maks_poz;i++){ w[tab[i].second]=1; } for(int i=0;i<n;i++){ if(w[i]==1){ cout<<"N"; } else{ cout<<"T"; } } return 0; } |