We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e03c383 commit 41aedb5Copy full SHA for 41aedb5
Array/Kth element/Kth smallest element.cpp
@@ -1,7 +1,7 @@
1
#include<bits/stdc++.h>
2
using namespace std;
3
int main(){
4
- priority_queue<int> min_heap;
+ priority_queue<int> max_heap;
5
int n,k;
6
cin>>n>>k;
7
@@ -11,21 +11,21 @@ int main(){
11
12
for(int i=0 ;i<n ;i++)
13
{
14
- if(min_heap.size()<k )
+ if(max_heap.size()<k )
15
16
- min_heap.push(a[i]);
+ max_heap.push(a[i]);
17
}
18
else
19
20
- if(min_heap.top()>a[i])
+ if(max_heap.top()>a[i])
21
22
- min_heap.pop();
23
+ max_heap.pop();
24
25
26
27
28
- cout<<min_heap.top()<<" ";
+ cout<<max_heap.top()<<" ";
29
30
return 0;
31
0 commit comments