#include <iostream> #include <vector> #include <algorithm> using namespace std; const int maxN = 5e5+5; int a[maxN]; vector<int> ryby; bool czyZostanieKrolem(int rozmiar) { long long suma = rozmiar; for(int i = 0; i < ryby.size(); i++) { if(i == 0 && rozmiar == ryby[i]) continue; if(ryby[i] == rozmiar && ryby[i] != ryby[i-1]) continue; if(suma <= ryby[i]) return 0; else suma += ryby[i]; } return true; } void solve() { int n, tmp, lo, hi, mid, ryba_max = 1e9+5; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ryby.push_back(a[i]); } sort(ryby.begin(), ryby.end()); lo = 0; hi = n - 1; while (lo <= hi) { mid = (lo + hi) / 2; if(czyZostanieKrolem(ryby[mid])) { ryba_max = ryby[mid]; hi = mid - 1; } else lo = mid + 1; } for(int i = 1; i <= n; i++) { if(a[i] >= ryba_max) cout << "T"; else cout << "N"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <vector> #include <algorithm> using namespace std; const int maxN = 5e5+5; int a[maxN]; vector<int> ryby; bool czyZostanieKrolem(int rozmiar) { long long suma = rozmiar; for(int i = 0; i < ryby.size(); i++) { if(i == 0 && rozmiar == ryby[i]) continue; if(ryby[i] == rozmiar && ryby[i] != ryby[i-1]) continue; if(suma <= ryby[i]) return 0; else suma += ryby[i]; } return true; } void solve() { int n, tmp, lo, hi, mid, ryba_max = 1e9+5; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ryby.push_back(a[i]); } sort(ryby.begin(), ryby.end()); lo = 0; hi = n - 1; while (lo <= hi) { mid = (lo + hi) / 2; if(czyZostanieKrolem(ryby[mid])) { ryba_max = ryby[mid]; hi = mid - 1; } else lo = mid + 1; } for(int i = 1; i <= n; i++) { if(a[i] >= ryba_max) cout << "T"; else cout << "N"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } |