#include <iostream> #include <vector> //#include <bits/stdc++.h> using namespace std; #define FORE(x, b, e) for(int x = b; x <= (e); ++x) #define FORL(x, b, e) for(int x = b; x < (e); ++x) #define P(x) cout <<#x <<'=' <<(x) <<" "; #define PP cout <<endl; #define Pv(x,a,b) cout << #x<<'=';for(int i=a;i<=b;i++)cout<<' '<<x[i];PP #define Pvv(x,y,a,b) cout <<#x <<#y <<'=';FORE(i,a,b)cout<<' '<<x[y[i]];PP /* typedef long long INT; typedef unsigned long long UINT; typedef vi vector<int>; UINT MOD = 1000000007ULL; */ #define MAX 120 int N[MAX+1]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); int u,k,v; cin >>u >>k; FORL(i,0,u){ cin >>v; N[v]++; } int s=0; for(int i=MAX;i>0;i--) { s+=N[i]; if(s>=k) break; } cout <<s <<endl; 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 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <vector> //#include <bits/stdc++.h> using namespace std; #define FORE(x, b, e) for(int x = b; x <= (e); ++x) #define FORL(x, b, e) for(int x = b; x < (e); ++x) #define P(x) cout <<#x <<'=' <<(x) <<" "; #define PP cout <<endl; #define Pv(x,a,b) cout << #x<<'=';for(int i=a;i<=b;i++)cout<<' '<<x[i];PP #define Pvv(x,y,a,b) cout <<#x <<#y <<'=';FORE(i,a,b)cout<<' '<<x[y[i]];PP /* typedef long long INT; typedef unsigned long long UINT; typedef vi vector<int>; UINT MOD = 1000000007ULL; */ #define MAX 120 int N[MAX+1]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); int u,k,v; cin >>u >>k; FORL(i,0,u){ cin >>v; N[v]++; } int s=0; for(int i=MAX;i>0;i--) { s+=N[i]; if(s>=k) break; } cout <<s <<endl; return 0; } |