fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include <set>
  5.  
  6. using namespace std;
  7. int main() {
  8.  
  9. set<long long int>s;
  10. set<long long int>::iterator it;
  11.  
  12. long long int t;
  13.  
  14. string a;
  15.  
  16. long long int tmp = 0;
  17. long long int ln;
  18. long long int nm = 1;
  19. long long int mxm = 0;
  20. bool negative = false;
  21.  
  22. while(!cin.eof()) {
  23.  
  24. cin >> t;
  25. getline(cin,a);
  26. ln = a.length();
  27. a+=" ";
  28. for(int i = 1;i<ln;++i) {
  29. if(!isspace(a[i])) {
  30. if(a[i] == '-') {negative = true;++i;}
  31. while(!isspace(a[i])) {
  32. tmp*=10;
  33. tmp+=(int)a[i]-48;
  34. ++i;
  35. }
  36. if(negative) tmp = -tmp;
  37. s.insert(tmp);
  38. tmp = 0;
  39. negative = false;
  40. }
  41. }
  42. for(it=s.begin();it!=s.end();++it) {
  43. mxm++;
  44. }
  45. if(mxm < t) cout << "-" << endl;
  46. else {
  47. for(it=s.begin();it!=s.end();++it) {
  48. if(mxm == t) {
  49. cout << *it << endl;
  50. break;
  51. }
  52. mxm--;
  53. }
  54. }
  55.  
  56. s.clear();
  57. mxm = 0;
  58. }
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 3468KB
stdin
3 10 20 30
4 10 20 30 30
2 1 2 6 8 9
1 16 16 18
stdout
10
-
8
18