#include <iostream> #include <algorithm> using namespace std; pair<int, int> sumy[500000]; bool krol[500000]; void solution(int& n) { int pref = 0; int x = 0; for(int i = 0; i < n; i++) { bool czykrol = 1; int sum = pref + sumy[i].first; for(int j = i + 1; j < n; j++) { if(sum > sumy[j].first) { sum += sumy[j].first; } else { czykrol = 0; } } if(czykrol) { krol[sumy[i].second] = 1; } if(sumy[i].first == sumy[i + 1].first) { x++; } else { pref += x * sumy[i].first; x = 0; } } for(int i = 0; i < n; i++) { if(krol[i]) { cout << "T"; } else { cout << "N"; } } } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; if(n == 1) { cout << "T"; return 0; } for(int i = 0; i < n; i++) { cin >> sumy[i].first; sumy[i].second = i; } sort(sumy, sumy + n); solution(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 | #include <iostream> #include <algorithm> using namespace std; pair<int, int> sumy[500000]; bool krol[500000]; void solution(int& n) { int pref = 0; int x = 0; for(int i = 0; i < n; i++) { bool czykrol = 1; int sum = pref + sumy[i].first; for(int j = i + 1; j < n; j++) { if(sum > sumy[j].first) { sum += sumy[j].first; } else { czykrol = 0; } } if(czykrol) { krol[sumy[i].second] = 1; } if(sumy[i].first == sumy[i + 1].first) { x++; } else { pref += x * sumy[i].first; x = 0; } } for(int i = 0; i < n; i++) { if(krol[i]) { cout << "T"; } else { cout << "N"; } } } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; if(n == 1) { cout << "T"; return 0; } for(int i = 0; i < n; i++) { cin >> sumy[i].first; sumy[i].second = i; } sort(sumy, sumy + n); solution(n); return 0; } |