#include <iostream> #include <vector> #include <algorithm> using namespace std; class Sum { public: int nr; long waga; int krol = 0; }; int main() { int n; cin >> n; vector<Sum> sumy(n); for(int i = 0; i < n; i++) { sumy[i].nr = i; cin >> sumy[i].waga; } sort(sumy.begin(), sumy.end(), [ ]( const Sum& lhs, const Sum& rhs ){ return lhs.waga < rhs.waga; }); long long suma_wag = 0; int i = 0; int waga0 = sumy[0].waga; while(i<n && sumy[i].waga== waga0) { suma_wag += sumy[i].waga; sumy[i].krol = -1; i++; } for( ; i < n; i++){ if(suma_wag <= sumy[i].waga) { for(int j = i-1; j >= 0; j--) { if(sumy[j].krol == -1) break; sumy[j].krol = -1; } } suma_wag += sumy[i].waga; } sort(sumy.begin(), sumy.end(), [ ]( const Sum& lhs, const Sum& rhs ){ return lhs.nr < rhs.nr; }); for(auto s : sumy) { if(s.krol == -1) cout << 'N'; else cout << 'T'; } cout << endl; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; class Sum { public: int nr; long waga; int krol = 0; }; int main() { int n; cin >> n; vector<Sum> sumy(n); for(int i = 0; i < n; i++) { sumy[i].nr = i; cin >> sumy[i].waga; } sort(sumy.begin(), sumy.end(), [ ]( const Sum& lhs, const Sum& rhs ){ return lhs.waga < rhs.waga; }); long long suma_wag = 0; int i = 0; int waga0 = sumy[0].waga; while(i<n && sumy[i].waga== waga0) { suma_wag += sumy[i].waga; sumy[i].krol = -1; i++; } for( ; i < n; i++){ if(suma_wag <= sumy[i].waga) { for(int j = i-1; j >= 0; j--) { if(sumy[j].krol == -1) break; sumy[j].krol = -1; } } suma_wag += sumy[i].waga; } sort(sumy.begin(), sumy.end(), [ ]( const Sum& lhs, const Sum& rhs ){ return lhs.nr < rhs.nr; }); for(auto s : sumy) { if(s.krol == -1) cout << 'N'; else cout << 'T'; } cout << endl; return 0; } |