fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, k;
  6. cin >> n >> k;
  7.  
  8. int a[50];
  9. for(int i = 0; i < n; i++) {
  10. cin >> a[i];
  11. }
  12.  
  13. int threshold = a[k - 1];
  14. int count = 0;
  15.  
  16. for(int i = 0; i < n; i++) {
  17. if(a[i] >= threshold && a[i] > 0) {
  18. count++;
  19. }
  20. }
  21.  
  22. cout << count << endl;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5324KB
stdin
8 5
10 9 8 7 7 7 5 5
stdout
6