#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5; const int INF = 1e9 + 999; int n; pair<int, int> sumy[MAX_N + 10]; bool krol[MAX_N + 10]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int a; for (int i = 1; i <= n; ++i) { cin >> a; sumy[i] = {i, a}; } sort(sumy + 1, sumy + n + 1, [](const pair<int,int> x, const pair<int,int> y){ return x.second < y.second; }); sumy[n + 1] = {n + 1, INF}; int i = 1; long long int masa_suma = 0; int id_suma = 0; while (sumy[i].second == sumy[i + 1].second) masa_suma += sumy[i++].second; masa_suma += sumy[i].second; masa_suma += sumy[++i].second; id_suma = i++; while (i <= n) { if (masa_suma <= sumy[i].second) id_suma = i; masa_suma += sumy[i++].second; } for (; id_suma <= n; ++id_suma) { krol[sumy[id_suma].first] = true; } for (int i = 1; i <= n; ++i) { if (krol[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 | #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5; const int INF = 1e9 + 999; int n; pair<int, int> sumy[MAX_N + 10]; bool krol[MAX_N + 10]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int a; for (int i = 1; i <= n; ++i) { cin >> a; sumy[i] = {i, a}; } sort(sumy + 1, sumy + n + 1, [](const pair<int,int> x, const pair<int,int> y){ return x.second < y.second; }); sumy[n + 1] = {n + 1, INF}; int i = 1; long long int masa_suma = 0; int id_suma = 0; while (sumy[i].second == sumy[i + 1].second) masa_suma += sumy[i++].second; masa_suma += sumy[i].second; masa_suma += sumy[++i].second; id_suma = i++; while (i <= n) { if (masa_suma <= sumy[i].second) id_suma = i; masa_suma += sumy[i++].second; } for (; id_suma <= n; ++id_suma) { krol[sumy[id_suma].first] = true; } for (int i = 1; i <= n; ++i) { if (krol[i]) cout << "T"; else cout << "N"; } } |