#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; constexpr int M = 5e5+7; constexpr int oo = 1e9+7; int t[M]; vector<int>vctr; bool check(int x, int n){ long long w = x; bool flag = 0; for(int i=0; i<n; i++){ if(!flag && vctr[i] == x) flag = 1; else if(vctr[i] < w) w += vctr[i]; else return false; } return true; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p, k, mid; cin >> n; for(int i=1; i<=n; i++){ cin >> t[i]; vctr.push_back(t[i]); } sort(vctr.begin(), vctr.end()); vctr.push_back(oo); p = 0; k = n; while(p < k){ mid = (p+k) >> 1; if(check(vctr[mid], n)) k = mid; else p = mid + 1; } for(int i=1; i<=n; i++) cout << ((t[i] >= vctr[p]) ? 'T' : '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 | #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; constexpr int M = 5e5+7; constexpr int oo = 1e9+7; int t[M]; vector<int>vctr; bool check(int x, int n){ long long w = x; bool flag = 0; for(int i=0; i<n; i++){ if(!flag && vctr[i] == x) flag = 1; else if(vctr[i] < w) w += vctr[i]; else return false; } return true; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p, k, mid; cin >> n; for(int i=1; i<=n; i++){ cin >> t[i]; vctr.push_back(t[i]); } sort(vctr.begin(), vctr.end()); vctr.push_back(oo); p = 0; k = n; while(p < k){ mid = (p+k) >> 1; if(check(vctr[mid], n)) k = mid; else p = mid + 1; } for(int i=1; i<=n; i++) cout << ((t[i] >= vctr[p]) ? 'T' : 'N'); return 0; } |