Skip to content

Commit 41aedb5

Browse files
authored
Update Kth smallest element.cpp
1 parent e03c383 commit 41aedb5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include<bits/stdc++.h>
22
using namespace std;
33
int main(){
4-
priority_queue<int> min_heap;
4+
priority_queue<int> max_heap;
55
int n,k;
66
cin>>n>>k;
77

@@ -11,21 +11,21 @@ int main(){
1111

1212
for(int i=0 ;i<n ;i++)
1313
{
14-
if(min_heap.size()<k )
14+
if(max_heap.size()<k )
1515
{
16-
min_heap.push(a[i]);
16+
max_heap.push(a[i]);
1717
}
1818
else
1919
{
20-
if(min_heap.top()>a[i])
20+
if(max_heap.top()>a[i])
2121
{
22-
min_heap.pop();
23-
min_heap.push(a[i]);
22+
max_heap.pop();
23+
max_heap.push(a[i]);
2424
}
2525
}
2626
}
2727

28-
cout<<min_heap.top()<<" ";
28+
cout<<max_heap.top()<<" ";
2929

3030
return 0;
3131
}

0 commit comments

Comments
 (0)