#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second const int N = 500500; int n; int a[N], b[N]; ll sum[N]; int main() { scanf("%d", &n); FOR(i,n) scanf("%d", &a[i]); FOR(i,n) b[i+1] = a[i]; sort(b,b+n+1); sum[0] = 0; FORI(i,n) sum[i] = sum[i-1] + b[i]; int gap = -1, ans = 1e9+7; FORI(i,n) if (sum[i] <= b[i+1]) gap = i; FORI(i,n) if (b[i] > b[gap]) { ans = b[i]; break; } FOR(i,n) putchar(a[i]<ans ? 'N' : 'T'); putchar('\n'); 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 | #include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second const int N = 500500; int n; int a[N], b[N]; ll sum[N]; int main() { scanf("%d", &n); FOR(i,n) scanf("%d", &a[i]); FOR(i,n) b[i+1] = a[i]; sort(b,b+n+1); sum[0] = 0; FORI(i,n) sum[i] = sum[i-1] + b[i]; int gap = -1, ans = 1e9+7; FORI(i,n) if (sum[i] <= b[i+1]) gap = i; FORI(i,n) if (b[i] > b[gap]) { ans = b[i]; break; } FOR(i,n) putchar(a[i]<ans ? 'N' : 'T'); putchar('\n'); return 0; } |