#include <bits/stdc++.h> using namespace std; int unsigned sum[500009] {}; int unsigned tab[500009] {}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,r=0,n2; long long unsigned suma=0; cin>>n; for (int i=0;i<n;i++) { cin>>tab[i]; sum[i]=tab[i]; suma=suma+sum[i]; } n2=n; n2--; sort(sum,sum+n); suma=suma-sum[n2]; r=sum[n2]; if (r==sum[0]) {r=INT_MAX;} else { while (sum[n2-1]>sum[0]) { if (suma>sum[n2]) {r=sum[n2-1]; suma=suma-r; n2--;} else {break;} } } for (int i=0;i<n;i++) {if (tab[i]>=r) {cout<<"T";} else {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 | #include <bits/stdc++.h> using namespace std; int unsigned sum[500009] {}; int unsigned tab[500009] {}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,r=0,n2; long long unsigned suma=0; cin>>n; for (int i=0;i<n;i++) { cin>>tab[i]; sum[i]=tab[i]; suma=suma+sum[i]; } n2=n; n2--; sort(sum,sum+n); suma=suma-sum[n2]; r=sum[n2]; if (r==sum[0]) {r=INT_MAX;} else { while (sum[n2-1]>sum[0]) { if (suma>sum[n2]) {r=sum[n2-1]; suma=suma-r; n2--;} else {break;} } } for (int i=0;i<n;i++) {if (tab[i]>=r) {cout<<"T";} else {cout<<"N";}} return 0; } |