题解 | #小乐乐改数字#
输入n个整数,输出其中最小的k个
http://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
用一下小堆 #include<bits/stdc++.h> using namespace std;
int main(){ int n,k; cin>>n>>k; priority_queue<int,vector,greater<>>q; for(int i=0;i<=n;i++){ int temp; scanf("%d",&temp); q.push(temp); } while(k--){ int res=q.top(); cout<<res<<" "; q.pop(); } return 0; }