懒虫小鑫

TimeLimit: 1000MS Memory Limit: 65536KB

SubmitStatistic

Problem Description

小鑫是个大懒虫,但是这一天妈妈要小鑫去山上搬些矿石去城里卖以补贴家用。小鑫十分的不开心。不开心归不开心,小鑫还是要做这件事情的。

我们把这个事情简化一下。有n块矿石,设第i块矿石由两个数字wipi表示。分别表示这块石头的重量和可以卖的价钱。小鑫每次只能搬一块矿石去城里卖,所以他决定每次都会搬重量最小的那块。如果恰好有几块重量相等,那就在这几块中挑选价值最高的带走。

由于路程原因。小鑫每天只能打m个来回,也就意味着他只能卖掉m块矿石。你能计算出他能得到多少钱么?

Input

输入数据有多组,到文件结束。

对于每一组数据,第一行为nmm≤n≤10000

接下来有n行,每行两个数代表石头的wp

Output

对于每组数据,输出有一行为一个数,为答案。

Example Input

4 2

1 2

1 3

2 2

3 4

Example Output

5

Hint

 

Author

lin


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
struct nodea
{

   double c,p;
   double j;
}node[10000000];
int cmp( const void*a,const void*b)
{
struct nodea *g =(nodea*)a;
struct nodea *d = (nodea*)b;
  if(  g->c!=d->c ) return g->c- d->c;
  else
  return d->j - g->j;


}
int main()
{
   int m,n;
   while(~scanf("%d%d",&n,&m))
   {

        for(int i=1;i<=n;i++)
        {

            scanf("%lf%lf",&node[i].c,&node[i].p);
            node[i].j = node[i].p/node[i].c;
        }
        qsort(&node[1],n,sizeof(node[1]),cmp);
        int sum = 0;
        for(int i=1;i<=m;i++)
        {
           sum += node[i].p;
        }
   printf("%d\n",sum);



   }




  return 0;

}


/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 84ms
Take Memory: 824KB
Submit time: 2017-01-11 19:23:06
****************************************************/