B - Mix Juice
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
A shop sells NN kinds of fruits, Fruit 1,…,N1,…,N, at prices of p1,…,pNp1,…,pN yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose KK kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.
- 1≤K≤N≤10001≤K≤N≤1000
- 1≤pi≤10001≤pi≤1000
- All values in input are integers.
Input is given from Standard Input in the following format:
NN KK
p1p1 p2p2 …… pNpN
Print an integer representing the minimum possible total price of fruits.
5 3
50 100 80 120 80
210
This shop sells Fruit 11, 22, 33, 44, and 55 for 5050 yen, 100100 yen, 8080 yen, 120120 yen, and 8080 yen, respectively.
The minimum total price for three kinds of fruits is 50+80+80=21050+80+80=210 yen when choosing Fruit 11, 33, and 55.
1 1
1000
1000
题意:输入一个n,然后输入n个数,找出前k小的数的和,并输出
思路:此题解法多种,可以是用优先队列来做也可以对数组排序来做。
优先队列:
#include
#include
using namespace std;
int main(void)
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
priority_queuep;//小顶堆
for(int i=0;i
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?


微信扫码登录