懒虫小鑫
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
输入
输出
示例输入
4 2 1 2 1 3 2 2 3 4
示例输出
5
提示
来源
示例程序
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
struct node
{
int w;
int p;
}q[10001];
int cmp(const void *a,const void *b)
{
struct node *aa,*bb;
aa=(struct node *)a;
bb=(struct node *)b;
if(aa->w!=bb->w)
return aa->w-bb->w;
else return bb->p-aa->p;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&q[i].w,&q[i].p);
}
qsort(q,n,sizeof(q[0]),cmp);
int l=0;
for(int i=0;i<m;i++)
{
l=l+q[i].p;
}
printf("%d\n",l);
}
return 0;
}