#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 352
/*
    重量*单价+重量*距离 = 重量*(距离+单价) 预处理单价
    贪心:优先买价格低的
*/
struct Node {
    int p;// p = (单价+距离)
    int w;
}c[N];

bool cmp(Node a, Node b)
{
    return a.p != b.p ? a.p < b.p : a.w > b.w;
}

int main()
{
    freopen("d:\\in.txt", "r", stdin);
    int t;
    int K, E, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%d%d", &K, &E, &n);
        int a, b;
        ; i<n; i++){
            scanf("%d%d%d", &a, &c[i].w, &b);
            c[i].p = E-a+b;
        }
        sort(c, c+n, cmp);
        , totw = ;
        ; i<n; i++){
            if(totw >= K) break;
            if(totw+c[i].w > K)
                res += c[i].p*(K-totw);
            else
                res += c[i].p*c[i].w;
            totw += c[i].w;
        }
        printf("%d\n", res);
    }
    ;
}

[河南省ACM省赛-第三届] BUYING FEED (nyoj 248)的更多相关文章

  1. [河南省ACM省赛-第三届] 素数 (nyoj 169)

    #include <iostream> #include <cstdio> #include <queue> #include <cstring> #i ...

  2. [河南省ACM省赛-第三届] 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...

  3. [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...

  4. [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...

  5. [河南省ACM省赛-第三届] 聪明的kk (nyoj 171)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171 动态规划: d(i,j) = max{d(i-1, j), d(i, j-1)}+m ...

  6. [河南省ACM省赛-第四届] 序号互换 (nyoj 303)

    相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...

  7. [河南省ACM省赛-第四届] 表达式求值(nyoj 305)

    栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  8. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  9. ACM BUYING FEED

    BUYING FEED 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 Farmer John needs to travel to town to pick up ...

随机推荐

  1. 如何编写makefile

    一:Makefile介绍: Makefile是为自动化编译而生.我们写好makefile文件后,只需要一个make命令,就可以完成整个项目的编译工作,大大提高了开发效率. 也许刚开始学习编程时,你不会 ...

  2. windows服务1053错误排查

    公司员工离职,接手他的任务,告诉我windows服务已经完成,没来得及测试.好吧,我接着做...... 服务生成后,运行bat文件.启动服务失败,提示错误编码1053.根据以往的经验,一般是三方面引起 ...

  3. Changing the working directory of VIM

    Sometimes we want to open another file in the same folder with current editing file, what we can do ...

  4. Android 下载模块分析(DownloadManager和DownloadProvider)

    Android下载模块主要有2个部分组成:DownloadManager和DownloadProvider:其中DownloadManager提供接口供调用,具体的实现是 DownloadProvid ...

  5. [置顶] “河软CSDN2011级表彰暨实习动员大会”顺利召开!

    9点30分 伴随着激昂的开场曲,主持人走到台前!“河软CSDN2011级表彰暨 实习动员大会即将开始,请各位嘉宾入场!”他们分别是“CSDN教育事业部总经 理李天山先生”“河北软件职业技术学院 软件工 ...

  6. [置顶] MyElipse9.0 M1安装svn(测试100%通过)

    为什么标题要写100%通过呢?原因是以前的方法(直接复制到plugin里(MyEclipse 6.0可以,我试过),link安装)都不好用了,9.0M1不吃这一套,所以告诉大家这么做一定能够装上!! ...

  7. 2440开发板linux系统移植3G拨号上网收发短信(三)

    一.用text查看模式 下面的“发”是指我敲的命令,“收”是指回车后显示的信息包括其他接收的信息. ~ >: microcom -s 115200 /dev/ttyUSB1 发:at 收:OK ...

  8. WIN7操作平台获取管理员权限批处理

    在WIN7操作平台打开某些文件,如果需要管理员权限才能打开.通过下面的操作就可以获取管理员权限 创建批处理register文件.文件内容为,文件后缀名为.reg.然后双击该文件.打开需要访问的文件,如 ...

  9. java异常处理01

    当我们做java项目的时候,多多少少都会出现一些异常,如何快速处理异常也将会影响到一个项目开发的进度. 以下将是面对的一些异常将如何去处理: 1.数据库没有启动 解决方法:计算机-->管理--& ...

  10. 软件各种版本的含义!例如RC,M,GA等等

    RC版本   RC:(Release Candidate)   Candidate是候选人的意思,用在软件上就是候选版本.Release是发行.发布的意思.Release.Candidate.就是发行 ...