#include<iostream> #include<map> #define rep(a,b) for(int a=0; a<(b); ++a) #define nl "\n" using namespace std; long long n, fishes[500007],min_req=0,prev_c=0; map<long long,long long> prefix; int main() { cin>>n; //prefix[0]=0; rep(i,n){ cin>>fishes[i]; prefix[fishes[i]]++; } pair<long long,long long> prev={0,0}; bool is=false; for(auto it:prefix){ //clog<<it.first<<" "<<it.second<<nl; if(is){ //clog<<prev_c<<" "<<prev.first<<" "<<prev.second<<nl; if((prev.first*prev.second)+prev_c<=it.first){ min_req=it.first; } prev_c+=prev.first*prev.second; } else{ min_req=it.first+1; is=true; //prev_c=it.first*it.second; //min_req=it.first; } //clog<<prev_c<<nl; prev=it; //clog<<min_req<<nl; } rep(i,n){ if(fishes[i]<min_req){ cout<<'N'; }else{ cout<<'T'; } } cout<<nl; 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 | #include<iostream> #include<map> #define rep(a,b) for(int a=0; a<(b); ++a) #define nl "\n" using namespace std; long long n, fishes[500007],min_req=0,prev_c=0; map<long long,long long> prefix; int main() { cin>>n; //prefix[0]=0; rep(i,n){ cin>>fishes[i]; prefix[fishes[i]]++; } pair<long long,long long> prev={0,0}; bool is=false; for(auto it:prefix){ //clog<<it.first<<" "<<it.second<<nl; if(is){ //clog<<prev_c<<" "<<prev.first<<" "<<prev.second<<nl; if((prev.first*prev.second)+prev_c<=it.first){ min_req=it.first; } prev_c+=prev.first*prev.second; } else{ min_req=it.first+1; is=true; //prev_c=it.first*it.second; //min_req=it.first; } //clog<<prev_c<<nl; prev=it; //clog<<min_req<<nl; } rep(i,n){ if(fishes[i]<min_req){ cout<<'N'; }else{ cout<<'T'; } } cout<<nl; return 0; } |