#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int sumNumber; cin >> sumNumber; vector<pair<int, int>> sums(sumNumber); vector<long long> prefixSum(sumNumber); vector<bool> kings(sumNumber); for (int i = 0; i < sumNumber; i++) { cin >> sums[i].first; sums[i].second = i; } sort(sums.begin(), sums.end()); prefixSum[0] = sums[0].first; for (int i = 1; i < sumNumber; i++) { prefixSum[i] = prefixSum[i - 1] + sums[i].first; } if (sums[sumNumber - 1].first > sums[sumNumber - 2].first || sums[sumNumber - 1].first > sums[0].first) { kings[sums[sumNumber- 1].second] = true; for (int i = sumNumber - 2; i > 0; i--) { if (sums[i].first > sums[i - 1].first || sums[i].first > sums[0].first) { if (prefixSum[i] > sums[i + 1].first) { kings[sums[i].second] = true; } else { break; } } else { break; } } } for (int i = 0; i < sumNumber; i++) { cout << (kings[i] ? "T" : "N"); } 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 | #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int sumNumber; cin >> sumNumber; vector<pair<int, int>> sums(sumNumber); vector<long long> prefixSum(sumNumber); vector<bool> kings(sumNumber); for (int i = 0; i < sumNumber; i++) { cin >> sums[i].first; sums[i].second = i; } sort(sums.begin(), sums.end()); prefixSum[0] = sums[0].first; for (int i = 1; i < sumNumber; i++) { prefixSum[i] = prefixSum[i - 1] + sums[i].first; } if (sums[sumNumber - 1].first > sums[sumNumber - 2].first || sums[sumNumber - 1].first > sums[0].first) { kings[sums[sumNumber- 1].second] = true; for (int i = sumNumber - 2; i > 0; i--) { if (sums[i].first > sums[i - 1].first || sums[i].first > sums[0].first) { if (prefixSum[i] > sums[i + 1].first) { kings[sums[i].second] = true; } else { break; } } else { break; } } } for (int i = 0; i < sumNumber; i++) { cout << (kings[i] ? "T" : "N"); } cout << endl; return 0; } |