#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n; cin>>n; vector<pair<long long, int>> V(n); vector<long long> S(n); for(int i=0; i<n; i++){ cin>>V[i].first; S[i]=V[i].first; V[i].second=i; } sort(V.begin(), V.end()); bool k; long long mini=2000000000; for(int i=0; i<n; i++){ long long K=S[i]; k = true; if(K < mini){ for(int j=0; j<n; j++){ if(V[j].second!=i){ if(K>V[j].first){ K+=V[j].first; } else{ k=false; break; } } } } if(k==true){ cout<<"T"; mini=min(S[i], mini); } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n; cin>>n; vector<pair<long long, int>> V(n); vector<long long> S(n); for(int i=0; i<n; i++){ cin>>V[i].first; S[i]=V[i].first; V[i].second=i; } sort(V.begin(), V.end()); bool k; long long mini=2000000000; for(int i=0; i<n; i++){ long long K=S[i]; k = true; if(K < mini){ for(int j=0; j<n; j++){ if(V[j].second!=i){ if(K>V[j].first){ K+=V[j].first; } else{ k=false; break; } } } } if(k==true){ cout<<"T"; mini=min(S[i], mini); } else cout<<"N"; } cout<<endl; return 0; } |