Gym 100513I - Sale in GameStore

在游戏店举办的促销活动中,玩家只需购买一款游戏即可免费下载更多游戏,总价值不得超过所购游戏价格。主角Polycarp利用此机会,通过朋友的支付承诺,最大化地获取游戏数量。

A well-known Berland onlinegames store has announced a great sale! Buy any game today, and you candownload more games for free! The only constraint is that the total price ofthe games downloaded for free can't exceed the price of the bought game.

When Polycarp found outabout the sale, he remembered that his friends promised him to cover any singlepurchase in GameStore. They presented their promise as a gift for Polycarp'sbirthday.

There are n gamesin GameStore, the price of the i-th game is pi. What is the maximumnumber of games Polycarp can get today, if his friends agree to cover theexpenses for any single purchase in GameStore?

Input

The first line of the inputcontains a single integer number n (1 ≤ n ≤ 2000) — the number of games in GameStore. The second linecontains n integer numbers p1, p2, ..., pn (1 ≤ pi ≤ 105), where pi is the price of the i-th game.

Output

Print the maximum number ofgames Polycarp can get today.

Sample test(s)

input

5
5 3 1 5 6

output

3

input

2
7 7

output

2

Note

In the first examplePolycarp can buy any game of price 5 or 6 and download games of prices 1 and 3for free. So he can get at most 3 games.

In the second examplePolycarp can buy any game and download the other one for free.

 

思路:

贪心,排序,取最大的数,从小的数开始减


程序:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 2005;

struct node
{
	int x, y;
};

int main()
{
	int n;
	scanf("%d\n", &n);
	int i;
	int p[N];
	for (i = 0; i<n; i++)
	{
		scanf("%d", &p[i]);
	}

	sort(p, p + n);

	int m = p[n - 1];

	int ans = 1;
	n--;
	for (i = 0; i<n; i++)
		if (m >= p[i])
		{
			m -= p[i];
			ans++;
		}

	printf("%d\n", ans);

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值