// C3 - Sumy #include <iostream> #include <vector> #include <algorithm> using namespace std; struct FishPot { long long weight; long long count; FishPot(int w, int c) { weight = w; count = c; } }; int main() { int n, a; int prev; long long currIndex, maxWeight; long long currWeight; vector<long long> fishListUnsorted; vector<long long> fishList; vector<FishPot> fishPots; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; fishList.push_back(a); fishListUnsorted.push_back(a); } sort(fishList.begin(), fishList.end()); prev = 0; for (int i = 1; i < n; ++i) { if (fishList[i - 1] < fishList[i]) { fishPots.push_back(FishPot(fishList[i - 1], i - prev)); prev = i; } } fishPots.push_back(FishPot(fishList[n - 1], n - prev)); maxWeight = fishList[n - 1]; if (fishPots.size() == 1) { for (int i = 0; i < n; ++i) { cout << 'N'; } return 0; } currIndex = 1; currWeight = fishPots[0].weight * fishPots[0].count + fishPots[1].weight * fishPots[1].count; for (unsigned i = 2; i < fishPots.size(); ++i) { if (currWeight <= fishPots[i].weight) { currIndex = i; } currWeight += fishPots[i].weight * fishPots[i].count; if (currWeight > maxWeight) { break; } } for (int i = 0; i < n; ++i) { cout << (fishListUnsorted[i] >= fishPots[currIndex].weight ? 'T' : '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 | // C3 - Sumy #include <iostream> #include <vector> #include <algorithm> using namespace std; struct FishPot { long long weight; long long count; FishPot(int w, int c) { weight = w; count = c; } }; int main() { int n, a; int prev; long long currIndex, maxWeight; long long currWeight; vector<long long> fishListUnsorted; vector<long long> fishList; vector<FishPot> fishPots; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; fishList.push_back(a); fishListUnsorted.push_back(a); } sort(fishList.begin(), fishList.end()); prev = 0; for (int i = 1; i < n; ++i) { if (fishList[i - 1] < fishList[i]) { fishPots.push_back(FishPot(fishList[i - 1], i - prev)); prev = i; } } fishPots.push_back(FishPot(fishList[n - 1], n - prev)); maxWeight = fishList[n - 1]; if (fishPots.size() == 1) { for (int i = 0; i < n; ++i) { cout << 'N'; } return 0; } currIndex = 1; currWeight = fishPots[0].weight * fishPots[0].count + fishPots[1].weight * fishPots[1].count; for (unsigned i = 2; i < fishPots.size(); ++i) { if (currWeight <= fishPots[i].weight) { currIndex = i; } currWeight += fishPots[i].weight * fishPots[i].count; if (currWeight > maxWeight) { break; } } for (int i = 0; i < n; ++i) { cout << (fishListUnsorted[i] >= fishPots[currIndex].weight ? 'T' : 'N'); } return 0; } |