1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 7 8 using namespace std; 9 10 struct node 11 { 12 double J; // JavaBean 13 double F; // Food 14 double rate; // 性价比 15 }arr[1000]; 16 17 bool cmp(node a, node b) 18 { 19 return a.rate > b.rate; 20 } 21 22 int main() 23 { 24 int m, n; 25 double a, b; 26 while(cin >> m >> n) 27 { 28 if(m == -1 && n == -1) 29 break; 30 31 for(int i = 0; i < n; ++i) 32 { 33 cin >> arr[i].J >> arr[i].F; 34 arr[i].rate = (arr[i].J) / (arr[i].F); 35 } 36 37 sort(arr, arr+n, cmp); 38 39 double ans = 0; 40 for(int i = 0; i < n; ++i) 41 { 42 if(m > arr[i].F) 43 { 44 ans += arr[i].J; 45 m -= arr[i].F; 46 } 47 else 48 { 49 ans += m*arr[i].rate; 50 break; 51 } 52 53 } 54 55 printf("%0.3f ", ans); 56 57 } 58 59 60 return 0; 61 }