Codeforces Gym 100513I I. Sale in gamestore violence

Source: Internet
Author: User
Tags integer numbers

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/gym/100513/problem/I

Description

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

When Polycarp found out about the sale, he remembered, he friends promised him to cover any single purchase in Gamest Ore. They presented their promise as a gift for Polycarp ' s birthday.

There was n Games in Gamestore, the price of the I--th game is pI. What's the maximum number of games Polycarp can get today, if he friends agree to cover the expenses for all single PURC Hase in Gamestore?

Input

The first line of the input contains a single integer number n (1≤ n ≤2000)-the number of GA Mes in Gamestore. The second line contains n integer numbers p1, P2, ..., p C13>n (1≤ pi ≤105), where pi was the price of The i-th game.

Output

Print the maximum number of games Polycarp can get today.

Sample Input

5
5 3 1) 5 6

Sample Output

3

HINT

Test instructions

Give you a bunch of games that tell you that you can buy a game, and you can donate something that doesn't exceed the value of the game.

Ask you how many games you can have in the final case of buying only one game

Exercises

Greedy, obviously this person buys the most expensive and then takes the cheapest few

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************intN;intA[MAXN];intSUM[MAXN];intMain () {intn=read ();  for(intI=1; i<=n;i++) A[i]=read (); Sort (a+1, A +1+N);  for(intI=1; i<=n;i++) Sum[i]=sum[i-1]+A[i];  for(inti=n-1; i>=1; i--)        if(sum[i]<=A[n]) {cout<<i+1<<Endl; return 0; } cout<<"1"<<Endl;}

Codeforces Gym 100513I I. Sale in gamestore violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.