您当前的位置: 首页 >  ui

MangataTS

暂无认证

  • 0浏览

    0关注

    423博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AtCoder Beginner Contest 171 B - Mix Juice

MangataTS 发布时间:2020-07-15 20:55:00 ,浏览量:0

B - Mix Juice

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

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.

Constraints
  • 1≤K≤N≤10001≤K≤N≤1000
  • 1≤pi≤10001≤pi≤1000
  • All values in input are integers.
Input

Input is given from Standard Input in the following format:

NN KK
p1p1 p2p2 …… pNpN

Output

Print an integer representing the minimum possible total price of fruits.

Sample Input 1 Copy
Copy
5 3
50 100 80 120 80

Sample Output 1 Copy
Copy
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.

Sample Input 2 Copy
Copy
1 1
1000

Sample Output 2 Copy
Copy
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            
关注
打赏
1665836431
查看更多评论
0.0373s