#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; class sumek{ public: sumek(){ } sumek(long long int x, long long int y, char c){ this->a = x; this->index = y; this->result = c; } friend bool operator< (sumek const& x, sumek const& y){ return x.a < y.a; }; friend bool operator> (sumek const& x, sumek const& y){ return x.index < y.index; }; long long int a; long long int index; char result; }; sumek s[500000+1]; int main(){ int n; cin >> n; long long int a; for(int i =0; i < n; ++i){ cin >> a; s[i] = sumek(a, i, 'N'); } sort(s, s+n, less<sumek>()); //for(int i = 0; i < n; ++i){ // cout << s[i].a; //} //cout << "\n"; long long int sum = s[0].a; bool p = false; int ks = -1; for(int i = 1; i < n; ++i){ //cout << "sum: " << sum << " a: " << s[i].a << "\n"; if(sum == s[i].a){ if(s[i-1].a==s[i].a){ ks = -1; }else{ ks = i; } } if(sum < s[i].a){ ks = i; } if(sum > s[i].a && ks == -1){ if(s[i-1].a==s[i].a){ ks = -1; }else{ ks = i; } } sum+=s[i].a; } for(int i = ks; i >= 0 && i < n; ++i){ s[i].result = 'T'; } sort(s, s+n, greater<sumek>()); //for(int i = 0; i < n; ++i){ // cout << s[i].a; //} //cout << "\n"; for(int i = 0; i < n; ++i){ cout << s[i].result; } cout << "\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 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 | #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; class sumek{ public: sumek(){ } sumek(long long int x, long long int y, char c){ this->a = x; this->index = y; this->result = c; } friend bool operator< (sumek const& x, sumek const& y){ return x.a < y.a; }; friend bool operator> (sumek const& x, sumek const& y){ return x.index < y.index; }; long long int a; long long int index; char result; }; sumek s[500000+1]; int main(){ int n; cin >> n; long long int a; for(int i =0; i < n; ++i){ cin >> a; s[i] = sumek(a, i, 'N'); } sort(s, s+n, less<sumek>()); //for(int i = 0; i < n; ++i){ // cout << s[i].a; //} //cout << "\n"; long long int sum = s[0].a; bool p = false; int ks = -1; for(int i = 1; i < n; ++i){ //cout << "sum: " << sum << " a: " << s[i].a << "\n"; if(sum == s[i].a){ if(s[i-1].a==s[i].a){ ks = -1; }else{ ks = i; } } if(sum < s[i].a){ ks = i; } if(sum > s[i].a && ks == -1){ if(s[i-1].a==s[i].a){ ks = -1; }else{ ks = i; } } sum+=s[i].a; } for(int i = ks; i >= 0 && i < n; ++i){ s[i].result = 'T'; } sort(s, s+n, greater<sumek>()); //for(int i = 0; i < n; ++i){ // cout << s[i].a; //} //cout << "\n"; for(int i = 0; i < n; ++i){ cout << s[i].result; } cout << "\n"; return 0; } |