ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

D - Powerful Discount Tickets

2019-09-16 21:01:51  阅读:287  来源: 互联网

标签:Tickets yen 1000000000 Powerful Sample Discount item Input Copy


D - Powerful Discount Tickets


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400400 points

Problem Statement

Takahashi is going to buy NN items one by one.

The price of the ii-th item he buys is AiAi yen (the currency of Japan).

He has MM discount tickets, and he can use any number of them when buying an item.

If YY tickets are used when buying an item priced XX yen, he can get the item for X2YX2Y (rounded down to the nearest integer) yen.

What is the minimum amount of money required to buy all the items?

Constraints

  • All values in input are integers.
  • 1≤N,M≤1051≤N,M≤105
  • 1≤Ai≤1091≤Ai≤109

Input

Input is given from Standard Input in the following format:

NN MM
A1A1 A2A2 ...... ANAN

Output

Print the minimum amount of money required to buy all the items.


Sample Input 1 Copy

Copy

3 3
2 13 8

Sample Output 1 Copy

Copy

9

We can buy all the items for 99 yen, as follows:

  • Buy the 11-st item for 22 yen without tickets.
  • Buy the 22-nd item for 33 yen with 22 tickets.
  • Buy the 33-rd item for 44 yen with 11 ticket.

Sample Input 2 Copy

Copy

4 4
1 9 3 5

Sample Output 2 Copy

Copy

6

Sample Input 3 Copy

Copy

1 100000
1000000000

Sample Output 3 Copy

Copy

0

We can buy the item priced 10000000001000000000 yen for 00 yen with 100000100000 tickets.


Sample Input 4 Copy

Copy

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

 

Takahashi将购买N.ñ 物品一个接一个。

该的价格我一世他买的第一项是A i一种一世 日元(日本的货币)。

他有M.中号 折扣票,他可以在购买物品时使用任意数量的票。

如果是Y.ÿ购买价格为X的商品时使用门票X日元,他可以获得X 2 Y的项目X2ÿ (向下舍入到最接近的整数)日元。

购买所有物品所需的最低金额是多少?

#include<bits/stdc++.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	priority_queue<int>q;    //优先队列自动从大到小排序
	int m,n,t;
	cin >>n>>m;
	for(int i=0;i<n;i++){
		cin>>t;
		q.push(t);    //每输入一个数都入队
	}
	long long sum=0;
	while(m){
		t=q.top()/2;
		q.pop();
		q.push(t);
		m--;
	}
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum;    //输出都处理完的总和
	return 0;
}

 

标签:Tickets,yen,1000000000,Powerful,Sample,Discount,item,Input,Copy
来源: https://blog.csdn.net/weixin_44423850/article/details/100901180

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有