fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,k,p[50],t[50],c[50];
  7. cin>>n>>k;
  8. for(int i=0;i<n;i++){
  9. cin>>p[i]>>t[i];
  10. c[p[i]]=t[i];
  11. }
  12. sort(p,p+n);
  13. reverse(p,p+n);
  14. for(int i=0;i<n;i++){
  15. if(p[i]==p[i+1]){
  16. if(c[p[i]]<c[p[i+1]])
  17. swap(p[i],p[i+1]);
  18. }
  19. }
  20. int x=p[k-1];
  21. int y=c[p[k-1]];
  22. int count=0;
  23. for(int i=0;i<n;i++){
  24. if(p[i]==x&&c[p[i]]==y)
  25. count++;
  26. }
  27. cout<<count;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3100KB
stdin
7 2
4 10
4 10
4 10
3 20
2 1
2 1
1 10
stdout
3