#include <bits/stdc++.h> #define N 2001 #define MOD 1e9+7 #define ll long long using namespace std; int n, k, a[N], ans; void read(){ cin>>n>>k; for(int i=1; i<=n; i++) cin>>a[i]; } int main(){ read(); sort(a+1, a+n+1, greater<int>()); ans=k; int last = a[k]; int i=k+1; while(a[i] == last){ ans++; i++; } cout<<ans; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <bits/stdc++.h> #define N 2001 #define MOD 1e9+7 #define ll long long using namespace std; int n, k, a[N], ans; void read(){ cin>>n>>k; for(int i=1; i<=n; i++) cin>>a[i]; } int main(){ read(); sort(a+1, a+n+1, greater<int>()); ans=k; int last = a[k]; int i=k+1; while(a[i] == last){ ans++; i++; } cout<<ans; return 0; } |