[Codeforces] 802M. April Fools' Problem (easy)

題目連結:http://codeforces.com/problemset/problem/802/M
沒敘述的題目www
但其實應該不難猜到就是輸出前k小數字的和。
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	priority_queue<int,vector<int>,greater<int>> pq;
	int n, k; cin>>n>>k;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		pq.push(x);
	}
	int ans = 0;
	for(int i=0;i<k;i++){
		ans += pq.top();
		pq.pop();
	}
	cout<<ans<<'\n';
	return 0;
}

留言

這個網誌中的熱門文章

[TIOJ] 1902. 「殿仁.王,不認識,誰啊?」,然後他就死了……

[AtCoder] [經典競程 90 題] 024 - Select +/- One(★2)

[AtCoder] [經典競程 90 題] 022 - Cubic Cake(★2)