#include<iostream> #include<vector> #include <algorithm> #include<set> using namespace std; bool cmp_weight(pair<int,int> a, pair<int,int> b) { return a.first < b.first; } bool cmp_index(pair<int,int> & a, pair<int,int> & b) { return a.second < b.second; } void wyp_waga(vector<pair<int,int>> tmp) { for(int i = 0; i < (int)tmp.size(); i++) { cout<<tmp[i].first<< " "<<tmp[i].second<<endl; } cout<<endl; } int main() { int n; cin>>n; vector<pair<int,int>> fish(n,{0,0}); vector<long long> sum(n); vector<long long> shorted_weight; vector<char> result(n,'-'); for(int i = 0; i < n; i++){ cin>>fish[i].first; fish[i].second = i; } sort(fish.begin(),fish.end(),cmp_weight); sum[0] = fish[0].first; for(int i = 1 ; i < n; i++) sum[i] = sum[i-1] + fish[i].first; //wyp_waga(fish); //for(auto cur : sum) cout<<cur<<" ";cout<<endl; result[fish[0].second] = 'N'; for(int candid = n-1; candid >= 0; candid--){ //if(candid % 10000) cout<<candid<<endl; if(fish[candid].first == fish[0].first){ result[fish[candid].second] = 'N'; } else if(fish[candid].first == fish[fish.size()-1].first){ result[fish[candid].second] = 'T'; } else{ if(sum[candid] > fish[candid+1].first){ result[fish[candid].second] = result[fish[candid+1].second]; } else{ result[fish[candid].second] = 'N'; } } } for(int i = 0; i < n; i++) cout<<result[i]; cout<<endl; }
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 | #include<iostream> #include<vector> #include <algorithm> #include<set> using namespace std; bool cmp_weight(pair<int,int> a, pair<int,int> b) { return a.first < b.first; } bool cmp_index(pair<int,int> & a, pair<int,int> & b) { return a.second < b.second; } void wyp_waga(vector<pair<int,int>> tmp) { for(int i = 0; i < (int)tmp.size(); i++) { cout<<tmp[i].first<< " "<<tmp[i].second<<endl; } cout<<endl; } int main() { int n; cin>>n; vector<pair<int,int>> fish(n,{0,0}); vector<long long> sum(n); vector<long long> shorted_weight; vector<char> result(n,'-'); for(int i = 0; i < n; i++){ cin>>fish[i].first; fish[i].second = i; } sort(fish.begin(),fish.end(),cmp_weight); sum[0] = fish[0].first; for(int i = 1 ; i < n; i++) sum[i] = sum[i-1] + fish[i].first; //wyp_waga(fish); //for(auto cur : sum) cout<<cur<<" ";cout<<endl; result[fish[0].second] = 'N'; for(int candid = n-1; candid >= 0; candid--){ //if(candid % 10000) cout<<candid<<endl; if(fish[candid].first == fish[0].first){ result[fish[candid].second] = 'N'; } else if(fish[candid].first == fish[fish.size()-1].first){ result[fish[candid].second] = 'T'; } else{ if(sum[candid] > fish[candid+1].first){ result[fish[candid].second] = result[fish[candid+1].second]; } else{ result[fish[candid].second] = 'N'; } } } for(int i = 0; i < n; i++) cout<<result[i]; cout<<endl; } |