#include <iostream> #include <algorithm> using namespace std; const int maxN = 500000; int a[maxN + 3]; int b[maxN + 3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a+n); int curr = a[0]; int first = -1; long long sum = 0; for(int i = 0; i < n - 1; i++){ sum += a[i]; if(sum <= a[i+1]) curr = a[i+1]; if(first == -1 && a[i] > a[0]) first = a[i]; } if(first == -1) { first = a[n - 1] + (a[0] == a[n-1]); } // for(int i = 0; i<n; i++){ // cout<<a[i]<<" "; // } // cout<<curr<<" "<<first<<"\n"; curr = max(curr, first); // cout<<max(curr, first)<<"\n"; for(int i=0; i<n; i++) cout<< (b[i] >= curr ? "T" : "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 | #include <iostream> #include <algorithm> using namespace std; const int maxN = 500000; int a[maxN + 3]; int b[maxN + 3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a+n); int curr = a[0]; int first = -1; long long sum = 0; for(int i = 0; i < n - 1; i++){ sum += a[i]; if(sum <= a[i+1]) curr = a[i+1]; if(first == -1 && a[i] > a[0]) first = a[i]; } if(first == -1) { first = a[n - 1] + (a[0] == a[n-1]); } // for(int i = 0; i<n; i++){ // cout<<a[i]<<" "; // } // cout<<curr<<" "<<first<<"\n"; curr = max(curr, first); // cout<<max(curr, first)<<"\n"; for(int i=0; i<n; i++) cout<< (b[i] >= curr ? "T" : "N"); cout<<"\n"; } |