hdu 2187(贪心)
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1000 + 10;
int c;
int n, m;
struct Node{
int p;
int h;
}node[maxn];
bool cmp(Node a, Node b){ //升序
return a.p < b.p;
}
int main(){
cin>>c;
while(c--){
cin>>n>>m;
for(int i=0; i<m; i++){
cin>>node[i].p>>node[i].h;
}
sort(node, node + m, cmp);
double sum = 0;
for(int i=0; i<m; i++){
if(n == 0)
break;
if(node[i].p * node[i].h <= n){
n = n - node[i].p * node[i].h;
sum += node[i].h;
}
else{
sum += n * (1.0 / double(node[i].p));
break;
}
}
printf("%.2lf\n", sum);
}
return 0;
}