#include <bits/stdc++.h> using namespace std; using ll = long long; pair<ll, int> arr[500009]; bool res[500009]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> arr[i].first; arr[i].second = i; } sort(arr, arr+n); ll s = 0; int last = arr[0].first, curr = 0; while(arr[curr].first == last and curr < n) s += arr[curr++].first; while(curr < n) { last = arr[curr-1].first; s += arr[curr++].first; while(curr < n and s > arr[curr].first) s += arr[curr++].first; } for(int i = 0; i < n; i++) res[arr[i].second] = arr[i].first > last; for(int i = 0; i < n; i++) cout << (res[i] ? 'T' : 'N'); 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 | #include <bits/stdc++.h> using namespace std; using ll = long long; pair<ll, int> arr[500009]; bool res[500009]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> arr[i].first; arr[i].second = i; } sort(arr, arr+n); ll s = 0; int last = arr[0].first, curr = 0; while(arr[curr].first == last and curr < n) s += arr[curr++].first; while(curr < n) { last = arr[curr-1].first; s += arr[curr++].first; while(curr < n and s > arr[curr].first) s += arr[curr++].first; } for(int i = 0; i < n; i++) res[arr[i].second] = arr[i].first > last; for(int i = 0; i < n; i++) cout << (res[i] ? 'T' : 'N'); cout << '\n'; return 0; } |