#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; vector<int> ciag; vector<int> ciag2; vector<int> wynik; cin >> n >> k; int num; for (int i = 0; i < n; i++) { cin >> num; ciag.push_back(num); ciag2.push_back(num); } int a = 0; num = 0; sort(ciag2.begin(), ciag2.end()); for (int i = 1; i < ciag2.size(); i++) { if(ciag2[i] == ciag2[i-1]) ciag2.erase(ciag2.begin()+i); } while (num < k) { for (int i = 0; i < n; i++) { if (ciag[i] == ciag2[a]) { wynik.push_back(ciag2[a]); num++; if (num >= k) break; } } a++; } sort(wynik.begin(), wynik.end()); cout << "TAK\n"; for (int i = 1; i < wynik.size(); i++) { if(wynik[i] == wynik[i-1]) wynik.erase(wynik.begin()+i); } for (int i = 0; i < wynik.size(); i++) cout << wynik[i] << " "; cout << "\n"; }
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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; vector<int> ciag; vector<int> ciag2; vector<int> wynik; cin >> n >> k; int num; for (int i = 0; i < n; i++) { cin >> num; ciag.push_back(num); ciag2.push_back(num); } int a = 0; num = 0; sort(ciag2.begin(), ciag2.end()); for (int i = 1; i < ciag2.size(); i++) { if(ciag2[i] == ciag2[i-1]) ciag2.erase(ciag2.begin()+i); } while (num < k) { for (int i = 0; i < n; i++) { if (ciag[i] == ciag2[a]) { wynik.push_back(ciag2[a]); num++; if (num >= k) break; } } a++; } sort(wynik.begin(), wynik.end()); cout << "TAK\n"; for (int i = 1; i < wynik.size(); i++) { if(wynik[i] == wynik[i-1]) wynik.erase(wynik.begin()+i); } for (int i = 0; i < wynik.size(); i++) cout << wynik[i] << " "; cout << "\n"; } |