fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6. #define sz(x) x.size()
  7.  
  8. void fastio()
  9. {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11. #ifndef ONLINE_JUDGE
  12. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  13. #endif
  14. }
  15.  
  16. void solve()
  17. {
  18. int n, k;
  19. cin >> n >> k;
  20. int arr[n], cnt = 0;
  21. for(int i = 0; i < n; i++)
  22. {
  23. cin >> arr[i];
  24. if(arr[i] >= arr[k - 1] && arr[i] > 0)
  25. cnt++;
  26. }
  27. cout << cnt << nl;
  28. }
  29. int main()
  30. {
  31. fastio();
  32. int test = 1;
  33. //cin >> test;
  34. for (int tc = 1; tc <= test; tc++)
  35. {
  36. solve();
  37. }
  38. }
Success #stdin #stdout 0.01s 5220KB
stdin
8 5
10 9 8 7 7 7 5 5
stdout
6