// Template start # include <string> # include <vector> # include <algorithm> # include <iostream> # include <sstream> # include <fstream> # include <map> # include <set> # include <cstdio> # include <cmath> # include <cstdlib> # include <ctime> # include <iomanip> # define SZ (X) (INT (X. size () using namespace STD; int toint (string s) {istringstream sin (s); int t; sin> T; return t ;} template <class T> string tostring (t x) {ostrings Tream sout; sout <X; return sout. STR ();} typedef long int64; int64 toint64 (string s) {istringstream sin (s); int64 t; sin> T; return t ;} template <class T> T gcd (t a, t B) {if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} // template end (general) // hdoj greedy algorithm 1001 fatmouse 'trade # define array_size 1005int main () {int M, N; int A [array_size]; int B [array_size]; double C [array_size]; int index; int count; double JB; ifstream ifs ("shuju.txt ", IOS: In); While (CIN> m> N &&! (M =-1 & n =-1) // ifs> m> nifs {JB = 0; memset (A, 0, array_size ); memset (B, 0, array_size); memset (C, 0, array_size); For (INT I = 0; I <n; I ++) {// ifs> A [I]> B [I]; CIN> A [I]> B [I]; c [I] = (a [I] + 0.0)/B [I] ;}for (Int J = 0; j <n; j ++) {Index = 0; for (INT I = 1; I <n; I ++) {If (C [I]> C [Index]) {Index = I ;}} if (M <B [Index]) {JB + = m * C [Index]; C [Index] = 0; break;} else {M-= B [Index]; JB + = A [Index]; C [Index] = 0 ;}} cout <fixed <setprecision (3) <JB <Endl ;}}