#include <iostream> #include <algorithm> #include <vector> #include <utility> using namespace std; vector<pair<int, int>>pary; int srt1 (pair<int, int>first, pair<int, int>second) { return first.second<second.second; } int srt2 (pair<int, int>first, pair<int, int>second) { return first.first<second.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(); int a, b; long long sum, x, y; cin>>a; for(int i=0; i<a; i++) { cin>>b; pary.push_back(make_pair(i, b)); } sort(pary.begin(), pary.end(), srt1); sum=pary[0].second; y=pary[0].second; for(int j=0; j<a; j++) { if(pary[j+1].second>=sum) x=pary[j+1].second; sum+=pary[j+1].second; } sort(pary.begin(), pary.end(), srt2); for(int i=0; i<a; i++) { if(pary[i].second>=x && pary[i].second>y) 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 <iostream> #include <algorithm> #include <vector> #include <utility> using namespace std; vector<pair<int, int>>pary; int srt1 (pair<int, int>first, pair<int, int>second) { return first.second<second.second; } int srt2 (pair<int, int>first, pair<int, int>second) { return first.first<second.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(); int a, b; long long sum, x, y; cin>>a; for(int i=0; i<a; i++) { cin>>b; pary.push_back(make_pair(i, b)); } sort(pary.begin(), pary.end(), srt1); sum=pary[0].second; y=pary[0].second; for(int j=0; j<a; j++) { if(pary[j+1].second>=sum) x=pary[j+1].second; sum+=pary[j+1].second; } sort(pary.begin(), pary.end(), srt2); for(int i=0; i<a; i++) { if(pary[i].second>=x && pary[i].second>y) cout<<"T"; else cout<<"N"; } return 0; } |