#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define SIZE(a) ((int)a.size()) bool check_sum(int a, vector<pii> &v) { ll sum = v[a].first; for(int i=0; i < SIZE(v)-1; i++) { if(i == a) { continue; } if(sum <= v[i].first) { return false; } sum+=v[i].first; } return true; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<pii> v(n+1); for(int i=0; i < n; i++) { cin >> v[i].first; v[i].second = i; } v[n] = {int(1e9+1), n}; sort(v.begin(), v.end()); int left = 0, right = n; while(left < right) { int mid = (left+right)/2; if(check_sum(mid, v)) { right = mid; } else { left = mid+1; } } vector<int> res(n+1); for(int i=left; i < n; i++) { res[v[i].second] = 1; } for(int i=0; i < n; i++) { if(res[i]) { cout << "T"; } else { cout << "N"; } } cout << "\n"; }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define SIZE(a) ((int)a.size()) bool check_sum(int a, vector<pii> &v) { ll sum = v[a].first; for(int i=0; i < SIZE(v)-1; i++) { if(i == a) { continue; } if(sum <= v[i].first) { return false; } sum+=v[i].first; } return true; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<pii> v(n+1); for(int i=0; i < n; i++) { cin >> v[i].first; v[i].second = i; } v[n] = {int(1e9+1), n}; sort(v.begin(), v.end()); int left = 0, right = n; while(left < right) { int mid = (left+right)/2; if(check_sum(mid, v)) { right = mid; } else { left = mid+1; } } vector<int> res(n+1); for(int i=left; i < n; i++) { res[v[i].second] = 1; } for(int i=0; i < n; i++) { if(res[i]) { cout << "T"; } else { cout << "N"; } } cout << "\n"; } |