#include <iostream> #include <algorithm> #include <cstdint> const int N = 500000; int n; int64_t masses[N]; int64_t sortedMasses[N]; bool check(int index){ int64_t sum = sortedMasses[index]; for(int i = 0; i < n; i++){ if(i != index){ if(sum <= sortedMasses[i]){ return false; } sum += sortedMasses[i]; } } return true; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cin >> n; for(int i = 0; i < n; i++){ std::cin >> masses[i]; sortedMasses[i] = masses[i]; } std::sort(sortedMasses, sortedMasses + n); int beg = 0; int end = n; while(beg < end){ int mid = (beg + end)/2; if(check(mid)){ end = mid; } else { beg = mid+1; } } int minMass; if(beg == n){ minMass = sortedMasses[n-1] + 1; } else { minMass = sortedMasses[beg]; } for(int i = 0; i < n; i++){ if(masses[i] < minMass){ std::cout << 'N'; } else { std::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 63 64 65 66 | #include <iostream> #include <algorithm> #include <cstdint> const int N = 500000; int n; int64_t masses[N]; int64_t sortedMasses[N]; bool check(int index){ int64_t sum = sortedMasses[index]; for(int i = 0; i < n; i++){ if(i != index){ if(sum <= sortedMasses[i]){ return false; } sum += sortedMasses[i]; } } return true; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cin >> n; for(int i = 0; i < n; i++){ std::cin >> masses[i]; sortedMasses[i] = masses[i]; } std::sort(sortedMasses, sortedMasses + n); int beg = 0; int end = n; while(beg < end){ int mid = (beg + end)/2; if(check(mid)){ end = mid; } else { beg = mid+1; } } int minMass; if(beg == n){ minMass = sortedMasses[n-1] + 1; } else { minMass = sortedMasses[beg]; } for(int i = 0; i < n; i++){ if(masses[i] < minMass){ std::cout << 'N'; } else { std::cout << 'T'; } } return 0; } |