#include<bits/stdc++.h> using namespace std; #define FOR(i, a, n) for(decltype(n) i = (a), i##__ = (n); i <= i##__; i++) #define REP(i, n) FOR(i, 0, (n)-1) #define FORD(i, a, n) for(decltype(a) i = (a), i##__ = (n); i >= i##__; i--) #define REPD(i, n) FORD(i, (n)-1, 0) #define V vector #define ST first #define ND second #define EB emplace_back #define RS resize #define SZ(x) int(x.size()) #define ALL(x) x.begin(), x.end() #define OS ostream template<class A, class B> OS& operator<<(OS &os, pair<A, B> p) { return os << "(" << p.ST << ", " << p.ND << ")"; } template<class A> OS& operator<<(OS &os, V<A> v) { os << "{ "; for(auto e : v) os << e << " "; return os << "}"; } template<class A> OS& operator<<(OS &os, V<V<A>> v) { os << "[\n"; for(auto e : v) os << " " << e << "\n"; return os << "]"; } #ifdef DEBUG # define D(a...) a # define _D(a...) #else # define D(a...) # define _D(a...) a #endif # define I(a...) #a << ": " << a << "\n" # define J(a...) #a << ": " << a << " " using VI = V<int>; using VVI = V<VI>; using VVVI = V<VVI>; using II = pair<int, int>; using VII = V<II>; using VVII = V<VII>; using L = long long; using VL = V<L>; using VVL = V<VL>; using LI = pair<L, int>; using VB = V<bool>; using VVB = V<VB>; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI in(n); for (int i = 0; i < n; i++) cin >> in[i]; VI a = in; VL sum = {0}; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) sum.emplace_back(a[i] + sum.back()); VI zakres(n, 0); int threshold = int(1e9 + 1); for (int i = 1; i < n; i++) { D(cerr << "considering " << a[i] << "\n"); zakres[i] = zakres[i - 1]; while (zakres[i] <= i and a[i] + sum[zakres[i]] > a[zakres[i]]) zakres[i]++; while (zakres[i] < n and sum[zakres[i]] > a[zakres[i]]) zakres[i]++; D(cerr << "I think that " << I(zakres[i])); if (zakres[i] == n) { threshold = a[i]; break; } } for (int i = 0; i < n; i++) { if (in[i] >= threshold) cout << "T"; else cout << "N"; } 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 | #include<bits/stdc++.h> using namespace std; #define FOR(i, a, n) for(decltype(n) i = (a), i##__ = (n); i <= i##__; i++) #define REP(i, n) FOR(i, 0, (n)-1) #define FORD(i, a, n) for(decltype(a) i = (a), i##__ = (n); i >= i##__; i--) #define REPD(i, n) FORD(i, (n)-1, 0) #define V vector #define ST first #define ND second #define EB emplace_back #define RS resize #define SZ(x) int(x.size()) #define ALL(x) x.begin(), x.end() #define OS ostream template<class A, class B> OS& operator<<(OS &os, pair<A, B> p) { return os << "(" << p.ST << ", " << p.ND << ")"; } template<class A> OS& operator<<(OS &os, V<A> v) { os << "{ "; for(auto e : v) os << e << " "; return os << "}"; } template<class A> OS& operator<<(OS &os, V<V<A>> v) { os << "[\n"; for(auto e : v) os << " " << e << "\n"; return os << "]"; } #ifdef DEBUG # define D(a...) a # define _D(a...) #else # define D(a...) # define _D(a...) a #endif # define I(a...) #a << ": " << a << "\n" # define J(a...) #a << ": " << a << " " using VI = V<int>; using VVI = V<VI>; using VVVI = V<VVI>; using II = pair<int, int>; using VII = V<II>; using VVII = V<VII>; using L = long long; using VL = V<L>; using VVL = V<VL>; using LI = pair<L, int>; using VB = V<bool>; using VVB = V<VB>; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI in(n); for (int i = 0; i < n; i++) cin >> in[i]; VI a = in; VL sum = {0}; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) sum.emplace_back(a[i] + sum.back()); VI zakres(n, 0); int threshold = int(1e9 + 1); for (int i = 1; i < n; i++) { D(cerr << "considering " << a[i] << "\n"); zakres[i] = zakres[i - 1]; while (zakres[i] <= i and a[i] + sum[zakres[i]] > a[zakres[i]]) zakres[i]++; while (zakres[i] < n and sum[zakres[i]] > a[zakres[i]]) zakres[i]++; D(cerr << "I think that " << I(zakres[i])); if (zakres[i] == n) { threshold = a[i]; break; } } for (int i = 0; i < n; i++) { if (in[i] >= threshold) cout << "T"; else cout << "N"; } cout << "\n"; } |