When it comes to the Maya Civilization, we can quickly remind of a term called the end of the world. It's not difficult to understand why we choose to believe the prophecy (or we just assume it is true to entertain ourselves) if you know the other prophecies appeared in the Maya Calendar. For instance, it has accurately predicted a solar eclipse on July 22, 2009.

The ancient civilization, such as Old BabylonianhasAncient Egypt and etc, some features in common. One of them is the tomb because of the influence of the religion. At that time, the symbol of the tomb is the pyramid. Many of these structures featured a top platform upon which a smaller dedicatory building was constructed, associated with a particularMaya deity. Maya pyramid-like structures were also erected to serve as a place of interment for powerful rulers.

Now there are N coffin chambers in the pyramid waiting for building and the ruler has recruited some workers to work for Tdays. It takes ti days to complete the ith coffin chamber. The size of the ith coffin chamber is si. They use a very special method to calculate the reward for workers. If starting to build the ith coffin chamber when there are t days left, they can get t*si units of gold. If they have finished a coffin chamber, then they can choose another coffin chamber to build (if they decide to build the ith coffin chamber at the time t, then they can decide next coffin chamber at the time t-ti).

At the beginning, there are T days left. If they start the last work at the time t and the finishing time t-ti < 0, they will not get the last pay.

Input

There are few test cases.

The first line contains NT (1 ≤ N ≤ 3000,1 ≤ T ≤ 10000), indicating there are N coffin chambers to be built, and there areT days for workers working. Next N lines contains tisi (1 ≤ tisi ≤ 500).

All numbers are integers and the answer will not exceed 2^31-1.

Output

For each test case, output an integer in a single line indicating the maxminal units of gold the workers will get.

Sample Input

3 10
3 4
1 2
2 1

Sample Output

62

Hint

Start the second task at the time 10
Start the first task at the time 9
Start the third task at the time 6
The answer is 10*2+9*4+6*1=62

#include"iostream"
#include"algorithm"
#include"cstring"
#include"queue"
#include"cmath"
#include"cstdio"
#include"cstdlib"
using namespace std;
#define sr(x) scanf("%d",&x)
#define sc(x) printf("%d",x)
#define hh printf("\n")
#define mod 1000000007
#define MAX(x,y) (x>y?x:y)
struct PP
{
int t,s;
};
int comp(PP x,PP y)
{
double l1,l2;
l1=(double)x.s*1.0/x.t;
l2=(double)y.s*1.0/y.t;
if(fabs(l1-l2)>0.00001)return l1>l2;
return x.t<y.t;
}
int main()
{
int n,tt,ss,ll[],i,j;
while(scanf("%d%d",&n,&tt)!=EOF)
{
ss=;
PP dd[];
for(i=;i<n;i++)
{
sr(dd[i].t);sr(dd[i].s);
}
memset(ll,,sizeof(ll));
sort(dd,dd+n,comp);
for(i=;i<n;i++)
{
for(j=tt;j>=dd[i].t;j--)
{
ll[j]=MAX(ll[j],ll[j-dd[i].t]+dd[i].s*(tt-j+dd[i].t));
ss=MAX(ss,ll[j]);
}
}
printf("%d\n",ss);
}
return ;
}

Digging-贪心的更多相关文章

  1. D - Digging(01背包,贪心)

    D - Digging Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit St ...

  2. ZOJ 3689 Digging(贪心+dp)

    Digging Time Limit: 2 Seconds      Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...

  3. 【贪心】【HDU3177】 搬家问题

    </pre><pre name="code" class="cpp">#include <iostream> #includ ...

  4. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  5. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  10. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

随机推荐

  1. wifi认证Portal开发系列(三):portal协议

    中国移动WLAN业务PORTAL协议规范介绍 一.用户上线认证流程 上线流程完成用户账号的认证,并把认证结果通知Portal Server,Portal server将会通知WLAN用户并且显示相应的 ...

  2. Anaconda2

    Anaconda 是一个打包的python,一次把好多需要的包都安装好了.对于Python2.7把PyQt5都弄好了,不需要自己来编译! 看看这个 http://conda.pydata.org/do ...

  3. mysql 查排名

    SET @amount=0;  SET @rank=1;  SET @shunxu=0;  SELECT tmp2.id AS id,tmp2.name AS NAME,tmp2.amount AS ...

  4. 有关Cache –(1) linux list之中的Prefetc

    转载:http://www.kernelchina.org/node/1050 linux的list实现之中有如下东东: #define list_for_each(pos, head) \     ...

  5. uboot之bootm以及go命令的实现

    本文档简单介绍了uboot中用于引导内核的命令bootm的实现,同时分析了uImage文件的格式,还简单看了一下uboot下go命令的实现 作者: 彭东林 邮箱: pengdonglin137@163 ...

  6. windows 2008配置运行PHP5.5.X

    1.安装web5.0平台安装程序.web5.0平台安装程序:http://www.iis.net/downloads (实际上更方便的是用WebPlalform安装PHP:http://www.mic ...

  7. 总是想把Linux服务器上的重要文件备份到本地,在此转一篇实现windows和linux互传文件的文章

    尝试从windows xp向ubuntu11.10传文件 ubuntu使用的是ssh windows使用的是putty和其附带的pscp 首先配置ubuntu: 1.先使用netstat -tl或se ...

  8. Java基础教程:多线程基础(2)——线程间的通信

    Java基础教程:多线程基础(2)——线程间的通信 使线程间进行通信后,系统之间的交互性会更强大,在大大提高CPU利用率的同时还会使程序员对各线程任务在处理的过程中进行有效的把控与监督. 线程间的通信 ...

  9. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  10. OC中RAC编程block的基本使用

    在OC中block的基本使用 // // ViewController.h // RAC--test // // Created by Aaron on 17/1/17. // Copyright © ...