#include <iostream> #include <algorithm> #include <tuple> const int maxN = 500 * 1000 + 20; int n; std::pair<long long, int> a[maxN]; long long sum; char winner[maxN]; int main(){ std::cin >> n; for(int i = 0; i < n; i++){ std::cin >> a[i].first; a[i].second = i; } std::sort(a, a + n); sum = 0; for(int i = 0; i <= n - 2; i++){ sum += a[i].first; winner[a[i].second] = sum > a[i + 1].first && a[i].first > a[0].first; } /*for(int i = 0; i < n; i++) std::cout << a[i].first << " "; std::cout << "\n";*/ winner[a[n - 1].second] = a[n - 1].first > a[0].first; for(int i = n - 2; i >= 0; i--){ winner[a[i].second] = winner[a[i + 1].second] && winner[a[i].second]; } for(int i = 0; i < n; i++) winner[i] = winner[i] ? 'T' : 'N'; winner[n] = 0; std::cout << winner << "\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 | #include <iostream> #include <algorithm> #include <tuple> const int maxN = 500 * 1000 + 20; int n; std::pair<long long, int> a[maxN]; long long sum; char winner[maxN]; int main(){ std::cin >> n; for(int i = 0; i < n; i++){ std::cin >> a[i].first; a[i].second = i; } std::sort(a, a + n); sum = 0; for(int i = 0; i <= n - 2; i++){ sum += a[i].first; winner[a[i].second] = sum > a[i + 1].first && a[i].first > a[0].first; } /*for(int i = 0; i < n; i++) std::cout << a[i].first << " "; std::cout << "\n";*/ winner[a[n - 1].second] = a[n - 1].first > a[0].first; for(int i = n - 2; i >= 0; i--){ winner[a[i].second] = winner[a[i + 1].second] && winner[a[i].second]; } for(int i = 0; i < n; i++) winner[i] = winner[i] ? 'T' : 'N'; winner[n] = 0; std::cout << winner << "\n"; return 0; } |