#include <bits/stdc++.h> #define fi first #define sc second #define forn(i,p,k) for(int i=(p);i<=(k);++i) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int T[3000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; forn(i,1,n) cin>>T[i]; sort(T+1,T+n+1,[](int a, int b){return a>b;}); int ind = k; while(T[ind+1] == T[k]) ind++; cout<<ind<<"\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <bits/stdc++.h> #define fi first #define sc second #define forn(i,p,k) for(int i=(p);i<=(k);++i) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int T[3000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; forn(i,1,n) cin>>T[i]; sort(T+1,T+n+1,[](int a, int b){return a>b;}); int ind = k; while(T[ind+1] == T[k]) ind++; cout<<ind<<"\n"; } |