#include <iostream> using namespace std; int main() { unsigned long n, temp, min, j; bool king; cin >> n; unsigned long weight[n], sorted[n]; unsigned long long sum; for(unsigned long i = 0; i < n; i++) { cin >> weight[i]; sorted[i] = weight[i]; } for(unsigned long i = 0; i < n - 1; i++) { min = i; for(unsigned long j = i + 1; j < n; j++) { if(sorted[j] < sorted[min]) min = j; } temp = sorted[i]; sorted[i] = sorted[min]; sorted[min] = temp; } for(unsigned long i = 0; i < n; i++) { sum = weight[i]; j = 0; do { if(sorted[j] == weight[i]) { temp = j; sorted[j] = 2000000000; } j++; } while(sorted[j - 1] != 2000000000); king = true; j = 0; while(j < n && king) { if(sum > sorted[j]) sum += sorted[j]; else if(sorted[j] != 2000000000) king = false; j++; } sorted[temp] = weight[i]; if(king) 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 59 | #include <iostream> using namespace std; int main() { unsigned long n, temp, min, j; bool king; cin >> n; unsigned long weight[n], sorted[n]; unsigned long long sum; for(unsigned long i = 0; i < n; i++) { cin >> weight[i]; sorted[i] = weight[i]; } for(unsigned long i = 0; i < n - 1; i++) { min = i; for(unsigned long j = i + 1; j < n; j++) { if(sorted[j] < sorted[min]) min = j; } temp = sorted[i]; sorted[i] = sorted[min]; sorted[min] = temp; } for(unsigned long i = 0; i < n; i++) { sum = weight[i]; j = 0; do { if(sorted[j] == weight[i]) { temp = j; sorted[j] = 2000000000; } j++; } while(sorted[j - 1] != 2000000000); king = true; j = 0; while(j < n && king) { if(sum > sorted[j]) sum += sorted[j]; else if(sorted[j] != 2000000000) king = false; j++; } sorted[temp] = weight[i]; if(king) cout << "T"; else cout << "N"; } return 0; } |