#include <iostream> #include <vector> #include <algorithm> #define ll long long using namespace std; const ll N = 1e6+1; ll n; pair<ll,ll> t[N]; ll ilezje[N]; ll tempsum; bool czytak[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; if(n == 1) { cout << "T"; return 0; } for(ll i = 0; i < n; i++) { cin >> t[i].first; t[i].second = i; } sort(t,t+n); for(ll i = 1; i < n; i++) { if(t[i].first == t[i-1].first) { ilezje[i] = ilezje[i-1]; tempsum += t[i].first; } else { ilezje[i] = ilezje[i-1] + t[i-1].first + tempsum; tempsum = 0; } } // for(ll i = 0; i < n; i++) // { // cout << t[i].first << '\t'; // } // cout << endl; // for(ll i = 0; i < n; i++) // { // cout << ilezje[i] << '\t'; // } // cout << endl; ll i = 0; t[n].first = INT64_MAX; while(i < n) { ll start = i; ll ryba = t[i].first + ilezje[i]; if(i < n - 1 and ryba <= t[i+1].first) { i++; continue; } while(ryba > t[i+1].first and i < n) { ryba += t[i+1].first; i++; } if(i == n-1) { i = start; break; } } //i == start if(i == n - 1) { if(t[i].first != t[i-1].first) { czytak[t[i].second] = true; } } else for(; i < n; i++) czytak[t[i].second] = true; for(int i = 0; i < n; i++) { if(czytak[i]) cout << "T"; else 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include <iostream> #include <vector> #include <algorithm> #define ll long long using namespace std; const ll N = 1e6+1; ll n; pair<ll,ll> t[N]; ll ilezje[N]; ll tempsum; bool czytak[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; if(n == 1) { cout << "T"; return 0; } for(ll i = 0; i < n; i++) { cin >> t[i].first; t[i].second = i; } sort(t,t+n); for(ll i = 1; i < n; i++) { if(t[i].first == t[i-1].first) { ilezje[i] = ilezje[i-1]; tempsum += t[i].first; } else { ilezje[i] = ilezje[i-1] + t[i-1].first + tempsum; tempsum = 0; } } // for(ll i = 0; i < n; i++) // { // cout << t[i].first << '\t'; // } // cout << endl; // for(ll i = 0; i < n; i++) // { // cout << ilezje[i] << '\t'; // } // cout << endl; ll i = 0; t[n].first = INT64_MAX; while(i < n) { ll start = i; ll ryba = t[i].first + ilezje[i]; if(i < n - 1 and ryba <= t[i+1].first) { i++; continue; } while(ryba > t[i+1].first and i < n) { ryba += t[i+1].first; i++; } if(i == n-1) { i = start; break; } } //i == start if(i == n - 1) { if(t[i].first != t[i-1].first) { czytak[t[i].second] = true; } } else for(; i < n; i++) czytak[t[i].second] = true; for(int i = 0; i < n; i++) { if(czytak[i]) cout << "T"; else cout << "N"; } } |