fork download
  1. // Author : Nishanth Vijayan
  2. // Institution: IIT Ropar,India.
  3. //
  4. // Spoj : http://w...content-available-to-author-only...j.com/users/nishanth_v/
  5. // Codechef : http://w...content-available-to-author-only...f.com/users/nishanth_v
  6. // HackerEarth : http://w...content-available-to-author-only...h.com/users/nishanththegr8/
  7. // Facebook : https://w...content-available-to-author-only...k.com/NishanthTheGr8
  8. //
  9. // Motto : The Less You Give A Fuck, The Happier You'll Be. :)
  10.  
  11.  
  12. #include <iostream>
  13. #include <cstdio>
  14. #include <map>
  15. #include <set>
  16. #include <vector>
  17. #include <stack>
  18. #include <algorithm>
  19. #include <utility>
  20. #include <cmath>
  21. #include <string>
  22. #include <cstring>
  23.  
  24.  
  25. #define ABS(x) ((x)<0?-(x):(x))
  26. #define SQR(x) ((x)*(x))
  27. #define CUBE(x) ((x)*(x)*(x))
  28. #define pnl printf("\n");
  29. #define REP(i,n) for(__typeof(n) i=0;i<(n);i++)
  30. #define FOR(i,a,b) for(__typeof(b) i=(a);i<(b);++i)
  31. #define FORE(i,a,b) for(__typeof(b) i=(a);i<=(b);++i)
  32. #define FORD(i,a,b,d) for(__typeof(b) i=(a);i<(b);i+=(d))
  33. #define FORR(i,n,e) for(__typeof(n) i=(n);i>=(e);--i)
  34. #define FORRD(i,n,e,d) for(__typeof(n) i=(n);i>=(e);i-=(d))
  35. #define FOREACH(i,s) for(__typeof((s).begin()) i=(s).begin();i!=(s).end();i++)
  36. #define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
  37. #define FILL(a,b) memset(a,b,sizeof(a))
  38. #define pi acos(-1)
  39. #define LLI long long int
  40. #define gc getchar_unlocked
  41. #define pc putchar_unlocked
  42.  
  43. using namespace std;
  44.  
  45. LLI scanint()
  46. {
  47. register int c = gc();
  48. LLI x = 0;
  49. int neg = 0;
  50. for(;((c<48 || c>57) && c != '-');c = gc());
  51. if(c=='-') {neg=1;c=gc();}
  52. for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
  53. if(neg) x=-x;
  54. return x;
  55. }
  56.  
  57. void writeint (LLI n)
  58. {
  59. LLI N = n, rev, count = 0;
  60. rev = N;
  61. if (N == 0) { pc('0'); pc('\n'); return ;}
  62. while ((rev % 10) == 0) { count++; rev /= 10;}
  63. rev = 0;
  64. while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
  65. while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
  66. while (count--) pc('0');
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. int main(){
  74.  
  75. int T;
  76. LLI n,k,C[50010];
  77. cin>>T;
  78. while(T--){
  79. cin>>n>>k;
  80. FOR(i,0,n)C[i]=scanint();
  81. if(k>n) cout<<0<<endl;
  82. else{
  83. sort(C,C+n);
  84. cout<<C[n-k]<<endl;
  85. }
  86. }
  87.  
  88. return 0;
  89. }
Success #stdin #stdout 0s 3612KB
stdin
6
3 2
3 1 4
4 1
3 1 4 9
5 4
2 4 3 1 1
5 13
2 4 3 1 1
3 5
1 1 100
3 5
1 100 101 
stdout
3
9
1
0
0
0