#include <iostream> using namespace std; int *income, n, k; int main() { cin >> n; cin >> k; income = new int[n]; for (int i=0; i<n; i++){ cin >> income[i]; } if ((k==2) && (income[n-1] > income[0])){ cout << "NIE"; } else { int max =0, imax=0; for (int j=0; j<n;j++){ if (income[j]>max) { max = income[j]; imax = j; } } if ((income[0]!=max) && (income[n-1]==max) && (n-1==imax)){ cout << "NIE"; } else if (income[0]==max){ cout << "TAK" << endl; for (int i=1; i<k;i++){ cout << i << " "; } } else if (k>2){ cout << "TAK" << endl; if (imax>=k-2){ for (int i=1; i<k-2;i++){ cout << i << " "; } cout << imax << " "; cout << imax+1 << " "; } else{ for (int i=1; i<k;i++){ cout << i << " "; } } } else{ //k==2 int min =max, max2=0; for (int j=0; j<imax;j++){ if (income[j]<min) { min = income[j]; } } for (int j=imax+1; j<n;j++){ if (income[j]>max2) { max2 = income[j]; } } if (min>=max2){ cout << "TAK" << endl; cout << imax+1; } else{ cout << "NIE"; } } } 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 71 | #include <iostream> using namespace std; int *income, n, k; int main() { cin >> n; cin >> k; income = new int[n]; for (int i=0; i<n; i++){ cin >> income[i]; } if ((k==2) && (income[n-1] > income[0])){ cout << "NIE"; } else { int max =0, imax=0; for (int j=0; j<n;j++){ if (income[j]>max) { max = income[j]; imax = j; } } if ((income[0]!=max) && (income[n-1]==max) && (n-1==imax)){ cout << "NIE"; } else if (income[0]==max){ cout << "TAK" << endl; for (int i=1; i<k;i++){ cout << i << " "; } } else if (k>2){ cout << "TAK" << endl; if (imax>=k-2){ for (int i=1; i<k-2;i++){ cout << i << " "; } cout << imax << " "; cout << imax+1 << " "; } else{ for (int i=1; i<k;i++){ cout << i << " "; } } } else{ //k==2 int min =max, max2=0; for (int j=0; j<imax;j++){ if (income[j]<min) { min = income[j]; } } for (int j=imax+1; j<n;j++){ if (income[j]>max2) { max2 = income[j]; } } if (min>=max2){ cout << "TAK" << endl; cout << imax+1; } else{ cout << "NIE"; } } } return 0; } |