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. 安卓图片框架:universal-image-loader的高速使用

    在安卓开发过程中难免会遇到下面几个情况: 1.图片异步载入 2.图片缓存 3.图片显示 4.其他--(忘记了) 以上的这些情况,可能要自己去写不少代码去实现这些功能.并且对于一些新手,可能写了半天,发 ...

  2. Error occured processing XML &#39;Cannot find class [springmvc.extention.BeanArgumentResolver]&#39;.

    <Description Resource Path Location Type Error occured processing XML 'Cannot find class [springm ...

  3. Jackson 框架,轻易转换JSON【转】

    Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在 ...

  4. 一些DevExpress控件概况!!!!主要DocumentManager.WindowsUIView.Tile

    WinForms Controls The links below provide comprehensive information on using DevExpress WinForms pro ...

  5. java日期处理 calendar 和date

    抄的人家的,仅作学习使用. java Date获取 年月日时分秒     package com.util;   import java.text.DateFormat; import java.ut ...

  6. Android : Activity 和 TabActivity 共用一个OptionMenu

    在虚拟机上我可以用menu键打开OptionMenu,但是到了真机上没有menu键了.OptionMenu没有办法打开,所以只能采用google推荐到ActionBar.用右上角到三个点代替实体到me ...

  7. iOS 网络请求——post请求

    -(void)postRequest{ NSString *urlString = [NSString stringWithFormat:@"http://f1.netgears.cn:80 ...

  8. JAVA 年老代收集器 第10节

    JAVA 年老代收集器 第10节 上一章我们讲了新生代的收集器,那么这一章我们要讲的就是关于老年代的一些收集器.老年代的存活的一般是大对象以及生命很顽强的对象,因此新生代的复制算法很明显不能适应该区域 ...

  9. Phalcon 性能最高的php框架没有之一

    最近有个朋友说他们现在在用Phalcon框架开发项目,明显感觉性能有很大的提升,所有着手学习下这个高性能框架,网上是这样说的“虽然以C语言编写达到较高的效能,但相对的一项缺点就是在服务器上必须拥有管理 ...

  10. C++中重载、重写(覆盖)和隐藏的区别实例分析

    这篇文章主要介绍了C++中重载.重写(覆盖)和隐藏的区别,是C++面向对象程序设计非常重要的概念,需要的朋友可以参考下 本文实例讲述了C++中重载.重写(覆盖)和隐藏的区别,对于C++面向对象程序设计 ...