D - Powerful Discount Tickets

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;
}

 

上一篇:QT5 用户录入文字程序


下一篇:LeetCode 875. 爱吃香蕉的珂珂(二分查找)