P - Shopaholic

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld
& %llu

Description

Lindsay is a shopaholic. Whenever there is a discount of the kind where you can buy three items and only pay for two, she goes completely mad and feels a need to buy all items in the store. You have given up on curing her for this disease, but try to limit
its effect on her wallet.

You have realized that the stores coming with these offers are quite selective when it comes to which items you get for free; it is always the cheapest ones. As an example, when your friend comes to the counter with seven items, costing 400, 350, 300, 250,
200, 150, and 100 dollars, she will have to pay 1500 dollars. In this case she got a discount of 250 dollars. You realize that if she goes to the counter three times, she might get a bigger discount. E.g. if she goes with the items that costs 400, 300 and
250, she will get a discount of 250 the first round. The next round she brings the item that costs 150 giving no extra discount, but the third round she takes the last items that costs 350, 200 and 100 giving a discount of an additional 100 dollars, adding
up to a total discount of 350.

Your job is to find the maximum discount Lindsay can get.

Input

The first line of input gives the number of test scenarios, 1 <= t <= 20. Each scenario consists of two lines of input. The first gives the number of items Lindsay is buying, 1 <= n <= 20000. The next line gives the prices of these items,
1 <= pi <= 20000.

Output

For each scenario, output one line giving the maximum discount Lindsay can get by selectively choosing which items she brings to the counter at the same time.

Sample Input

1

6

400 100 200 350 300 250

Sample Output

400

my answer:

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int T,n;
cin>>T;
while(T--)
{
cin>>n;
int a[20002];
for(int i=0;i!=n;i++){
cin>>a[i];
}
sort(a,a+n,cmp);
if(n>=3){
int i=2,sum=0;
for(;i<n;i+=3){
sum+=a[i];
}
cout<<sum<<endl;
}
else
cout<<0<<endl;
}
return 0;
}

P - Shopaholic的更多相关文章

  1. HDOJ(HDU) 1678 Shopaholic

    Problem Description Lindsay is a shopaholic. Whenever there is a discount of the kind where you can ...

  2. 1438. Shopaholic

    Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Lindsay is a shopaholic. Whenever th ...

  3. ZOJ 2883 Shopaholic【贪心】

    解题思路:给出n件物品,每买三件,折扣为这三件里面最便宜的那一件即将n件物品的价值按降序排序,依次选择a[3],a[6],a[9]----a[3*k] Shopaholic Time Limit: 2 ...

  4. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  5. L1-Day1

    L1-Day11.我是一个网虫.(描述关系)[我的翻译]I am a net worm.[标准答案]I am a webaholic.[对比分析]我的worm是实实在在的虫子,本句话想表达的意思是对网 ...

  6. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  7. Maximal Discount

    Description: Linda is a shopaholic. Whenever there is a discount of the kind where you can buy three ...

  8. TAE words all

    // vol 1   could do with sth   rhinoplasty   angst   the wee small hours   familial   Munich   gladi ...

随机推荐

  1. OAuth2 for asp.net web api

    在上篇文章中我研究了OpenId及DotNetOpenAuth的相关应用,这一篇继续研究OAuth2. https://github.com/DotNetOpenAuth http://www.cnb ...

  2. Struts2 初体验

    Sturts是一款优雅的,可扩展性很强的框架.它是由Struts开发团队和WebWord团队合作,共同开发的一个新的产品.新版本的Struts2 更加容易使用,更加接近Struts所追求的理念.从开发 ...

  3. iOS状态栏字体设置为白色

    info.plist 添加字段: view controller -base status bar appearence 设为NO [[UIApplication sharedApplication] ...

  4. QT正则表达式

    QT正则表达式有一个问题,当初始状态是不符合正则表达式时,能够输入任意字符,若在输入过程中符合正则表达式,马上进入字符检测状态,即只能接受符合正则表达式的字符.

  5. shell脚本定时备份数据库

    脚本代码: 新建文件back_db.sh #!/bin/bash TODAYTIME="`date +%Y%m%d`" DBNAME="test mysql" ...

  6. Docker容器

    Docker容器 Docker容器 1. 容器基本操作 启动容器: 1.docker run IMAGE [COMMAND] [ARG...]2. 演示: 1.[KANO@kelvin ~]$ doc ...

  7. CSS3弹性盒模型布局模块

    原文:http://robertnyman.com/2010/12/02/css3-flexible-box-layout-module-aka-flex-box-introduction-and-d ...

  8. objective -c こだわり

    You make an object by creating an instance of a particular class. You do this by allocating the obje ...

  9. 使用verilog实现4选1数据选择器的几种方法

    第一种方法module mux( d1, d2, d3, d4, se1, se2, dout ); input d1; input d2; input d3; input d4; input se1 ...

  10. javascript学习笔记(2)

    <html> <head><title>Throwing die</title><script>    var canv_width  = ...