// Krzysztof Baranski (2021.12.08) #include <cstdio> #include <algorithm> using namespace std; int weights[500002]; int weights_sorted[500002]; int main() { int n; scanf("%d\n", &n); for(int i=0; i<n; ++i) { scanf("%d", weights+i); weights_sorted[i] = weights[i]; } sort(weights_sorted, weights_sorted+n); int min_king_index = 0; long long sum_weights = 0; for(int i=0; i<n-1; ++i) { sum_weights += weights_sorted[i]; if(sum_weights <= weights_sorted[i+1]) min_king_index = i; } int min_weight = weights_sorted[min_king_index]; for(int i=0; i<n; ++i) { printf("%c", weights[i] > min_weight ? 'T' : 'N'); } printf("\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 | // Krzysztof Baranski (2021.12.08) #include <cstdio> #include <algorithm> using namespace std; int weights[500002]; int weights_sorted[500002]; int main() { int n; scanf("%d\n", &n); for(int i=0; i<n; ++i) { scanf("%d", weights+i); weights_sorted[i] = weights[i]; } sort(weights_sorted, weights_sorted+n); int min_king_index = 0; long long sum_weights = 0; for(int i=0; i<n-1; ++i) { sum_weights += weights_sorted[i]; if(sum_weights <= weights_sorted[i+1]) min_king_index = i; } int min_weight = weights_sorted[min_king_index]; for(int i=0; i<n; ++i) { printf("%c", weights[i] > min_weight ? 'T' : 'N'); } printf("\n"); return 0; } |