#include <bits/stdc++.h> using namespace std; bool check; int n,k,wyn; int arr[2010]; int main(){ ios_base::sync_with_stdio(0); cin>>n>>k; for(int i=0;i<n;i++){ cin>>arr[i]; } sort(arr,arr+n); reverse(arr,arr+n); for(int i=0;i<n;i++){ //cout<<i<<" "<<arr[i]<<endl; if( (i+1==k or check) and arr[i]==arr[i+1] ){ wyn++; check=true; } else if(i+1==k) break; else if(check) break; } cout<<max(k,k+wyn)<<endl; }
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> using namespace std; bool check; int n,k,wyn; int arr[2010]; int main(){ ios_base::sync_with_stdio(0); cin>>n>>k; for(int i=0;i<n;i++){ cin>>arr[i]; } sort(arr,arr+n); reverse(arr,arr+n); for(int i=0;i<n;i++){ //cout<<i<<" "<<arr[i]<<endl; if( (i+1==k or check) and arr[i]==arr[i+1] ){ wyn++; check=true; } else if(i+1==k) break; else if(check) break; } cout<<max(k,k+wyn)<<endl; } |