#include <iostream> #include <algorithm> #include <vector> using namespace std; vector <int> kopia; int n; bool spr(int j){ long long pom = kopia[j]; for (int i = 0; i < n; i++){ if (i != j){ if (pom > kopia[i]){ pom += kopia[i]; }else{ return false; } } } return true; } int main() { cin >> n; vector <int> sum(n); for (int i = 0; i < n; i++){ cin >> sum[i]; } kopia = sum; sort(kopia.begin(), kopia.end()); int min = 0; int maks = n-1; int sr; while (min < maks) { sr = (min + maks)/2; if (spr(sr) == true){ maks = sr; }else{ min = sr+1; } } if (spr(min) == false) { for (int i = 0; i < n; i++){ cout << "N"; } }else{ for (int i = 0; i < n; i++){ if (sum[i] >= kopia[min]){ cout << "T"; }else{ cout << "N"; } } } 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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; vector <int> kopia; int n; bool spr(int j){ long long pom = kopia[j]; for (int i = 0; i < n; i++){ if (i != j){ if (pom > kopia[i]){ pom += kopia[i]; }else{ return false; } } } return true; } int main() { cin >> n; vector <int> sum(n); for (int i = 0; i < n; i++){ cin >> sum[i]; } kopia = sum; sort(kopia.begin(), kopia.end()); int min = 0; int maks = n-1; int sr; while (min < maks) { sr = (min + maks)/2; if (spr(sr) == true){ maks = sr; }else{ min = sr+1; } } if (spr(min) == false) { for (int i = 0; i < n; i++){ cout << "N"; } }else{ for (int i = 0; i < n; i++){ if (sum[i] >= kopia[min]){ cout << "T"; }else{ cout << "N"; } } } return 0; } |