I. Sale in GameStore(贪心)
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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 that the total price of the games downloaded for free can't exceed the price of the bought game.

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

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

Input

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

Output

Print the maximum number of games 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 example Polycarp can buy any game of price 5 or 6 and download games of prices 1 and 3 for free. So he can get at most 3 games.

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

代码能力还是太弱了(这题是贪心),排序后找

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int max_size = ; void quick_sort(int arry[], int l, int r)
{
if(l < r)
{
int i = l, j = r, k = arry[l];
while(i < j)
{
while(i < j && arry[j] >= k)
j--;
if(i < j)
arry[i++] = arry[j];
while(i < j && arry[i] < k)
i++;
if(i < j)
arry[j--] = arry[i];
} arry[i] = k;
quick_sort(arry, l, i-);
quick_sort(arry, i+, r);
}
} int main()
{
int n;
int arry[max_size];
/// (1 ≤ n ≤ 2000)
/// (1 ≤ pi ≤ 105)
while(scanf("%d", &n) != EOF)
{
memset(arry, , sizeof(arry));
for(int i = ; i < n; ++i)
{
scanf("%d", &arry[i]);
} quick_sort(arry, , n-); int max_price = arry[n-];
int total = ;
int num = ;
int j = ;
while(j < n-)
{
total += arry[j++];
if(total <= max_price)
num++;
}
printf("%d\n", num+);
}
return ;
}

F题感觉学长代码写得太风骚了,看不太懂,再加油

2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  2. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  3. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  5. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  8. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  9. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

  10. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. volatile和const

    volatile可理解为“编译器警告指示字” volatile用于告诉编译器必须每次去内存中取变量值 volatile主要修饰可能被多个线程访问的变量 volatile也可以修饰可能被未知因数更改的变 ...

  2. 设计模式之构建者模式(Builder):初步理解

    构建者(Builder)设计模式(又叫生成器设计模式): 当一个类的内部数据过于复杂的时候(通常是负责持有数据的类,比如Config.VO.PO.Entity...),要创建的话可能就需要了解这个类的 ...

  3. hud 2602 Bone Collector

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 思路:典型的01背包 #include<stdlib.h> #include< ...

  4. Jquery.Datatables 服务器处理(Server-side processing)

    看了看介绍 http://datatables.club/manual/server-side.html 没有经过处理的分页,先显示出来看看效果,就这样写(存储过程自己写) cshtml " ...

  5. SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable

    http://blog.csdn.net/isea533/article/details/33397735

  6. 与你相遇好幸运,Linux常用命令

    开机挂载硬盘 cat  /etc/fstab /dev/sda1  /mnt/sda1 ext3    defaults    0  0 挂载硬盘 mount  /dev/sdb5 /home/dis ...

  7. 22.访问者模式(Vistor Pattern)

    using System; using System.Collections; namespace ConsoleApplication5 { /// <summary> /// 访问者模 ...

  8. android:installLocation = "auto" 的用法

    在Froyo(android 2.2,API Level:8)中引入了android:installLocation.通过设置该属性可以使得开发者以及用户决定程序的安装位置. android:inst ...

  9. xml解析方法总结

    ==========================================xml文件<?xml version=”1.0″ encoding=”GB2312″?> <RES ...

  10. c++ 左值右值 函数模板

    1.先看一段代码,这就是一种函数模板的用法,但是红色的部分如果把a写成a++或者写成一个常量比如1,都是编译不过的,因为如果是a++的话,实际上首先是取得a的 值0,而0作为一个常量没有地址.写成1也 ...