题目链接:https://codeforces.com/contest/16/problem/B
#include <iostream>
#include <algorithm>
using namespace std
;
static const int MAXN
=20+10;
struct Node
{
int a
,b
;
bool operator<(const Node
&o
)const{
return b
>o
.b
;
}
}match
[MAXN
];
int n
,m
;
int main()
{
scanf("%d%d",&n
,&m
);
for(int i
=0;i
<m
;i
++)
scanf("%d%d",&match
[i
].a
,&match
[i
].b
);
sort(match
,match
+m
);
int ans
=0;
for(int i
=0;i
<m
;i
++)
{
if(match
[i
].a
>=n
)
{
ans
+=min(match
[i
].a
,n
)*match
[i
].b
;
break;
}
ans
+=match
[i
].a
*match
[i
].b
;
n
-=match
[i
].a
;
}
printf("%d\n",ans
);
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-8782.html