#include <cstdio> #include <vector> #include <algorithm> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) typedef unsigned long long int ulli; struct Fish { int size, pos; inline bool operator<(const Fish &other) { if (size!=other.size) return size < other.size; return pos<other.pos; } }; int n; int main() { scanf("%d", &n); vector<Fish> P(n); char result[n+1]; FOR(i,0,n) result[i] = 'N'; result[n] = 0; ulli S = 0; FOR(i,0,n) { P[i].pos = i; scanf("%d", &P[i].size); S += (ulli)(P[i].size); } sort(P.begin(), P.end()); int U = 0; FOR(i,0,n) { if (P[n-1-i].size<=P[0].size || (ulli)(S)<=(ulli)(U)) break; result[P[n-1-i].pos] = 'T'; S = S - P[n-1-i].size; U = max(P[n-1-i].size, U - P[n-1-i].size); } printf("%s\n", result); 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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) typedef unsigned long long int ulli; struct Fish { int size, pos; inline bool operator<(const Fish &other) { if (size!=other.size) return size < other.size; return pos<other.pos; } }; int n; int main() { scanf("%d", &n); vector<Fish> P(n); char result[n+1]; FOR(i,0,n) result[i] = 'N'; result[n] = 0; ulli S = 0; FOR(i,0,n) { P[i].pos = i; scanf("%d", &P[i].size); S += (ulli)(P[i].size); } sort(P.begin(), P.end()); int U = 0; FOR(i,0,n) { if (P[n-1-i].size<=P[0].size || (ulli)(S)<=(ulli)(U)) break; result[P[n-1-i].pos] = 'T'; S = S - P[n-1-i].size; U = max(P[n-1-i].size, U - P[n-1-i].size); } printf("%s\n", result); return 0; } |