#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5 * 100 * 1000 + 7; bool w[N]; pair<ll, int> tab[N]; void Solve() { int n, l, p; ll s = 0LL; cin >> n; for(int i = 1; i <= n; ++i) { cin >> tab[i].first; s += tab[i].first; tab[i].second = i; } sort(tab + 1, tab + 1 + n); l = n; p = 1; while(tab[p + 1].first == tab[p].first) ++p; while(s > tab[l + 1].first && l > p) { w[tab[l].second] = 1; s -= tab[l].first; --l; } for(int i = 1; i <= n; ++i) { if(w[i]) cout << "T"; else cout << "N"; } cout << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5 * 100 * 1000 + 7; bool w[N]; pair<ll, int> tab[N]; void Solve() { int n, l, p; ll s = 0LL; cin >> n; for(int i = 1; i <= n; ++i) { cin >> tab[i].first; s += tab[i].first; tab[i].second = i; } sort(tab + 1, tab + 1 + n); l = n; p = 1; while(tab[p + 1].first == tab[p].first) ++p; while(s > tab[l + 1].first && l > p) { w[tab[l].second] = 1; s -= tab[l].first; --l; } for(int i = 1; i <= n; ++i) { if(w[i]) cout << "T"; else cout << "N"; } cout << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solve(); return 0; } |