#include<bits/stdc++.h> using namespace std; typedef long long ll; #define SIZE(x) (int)x.size() #define REP(x,t) for(ll x=0; x<(t); x++) #define FOR(x,t) for(ll x=1; x<=(t); x++) #define pb(x) push_back(x) #define pf(x) push_front(x) #define st first #define nd second ll inf=1e9+7; ll mod=1e9+7; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; int w=k; priority_queue <int> Q; int x; REP(i,n){ cin>>x; Q.push(x); } while(!Q.empty()){ if(k>0){ k--; x=Q.top(); Q.pop(); } else{ if(Q.top()==x){ k--; Q.pop(); } else break; } } w-=k; cout<<w; 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 44 45 46 | #include<bits/stdc++.h> using namespace std; typedef long long ll; #define SIZE(x) (int)x.size() #define REP(x,t) for(ll x=0; x<(t); x++) #define FOR(x,t) for(ll x=1; x<=(t); x++) #define pb(x) push_back(x) #define pf(x) push_front(x) #define st first #define nd second ll inf=1e9+7; ll mod=1e9+7; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; int w=k; priority_queue <int> Q; int x; REP(i,n){ cin>>x; Q.push(x); } while(!Q.empty()){ if(k>0){ k--; x=Q.top(); Q.pop(); } else{ if(Q.top()==x){ k--; Q.pop(); } else break; } } w-=k; cout<<w; return 0; } |