HDOJ 1.3.1 FatMouse' Trade_
WA了 待调
using namespace std;
struct st{
double j; double f; double x;
bool operator < (const struct st&a )const{
return x > a.x;
}
}a[2000];
double res = 0.0; int p = 1;
int main() {
while(1){
double M; int N ; cin >> M >> N;
res = 0.0 ; p = 1;
if(N == -1 ) break;
for(int i =1 ; i <= N ; i++){
cin >> a[i].j >> a[i].f ;
if( a[i].f == 0 ) a[i].x = 100001.0;
else a[i].x = (double)a[i].j * 1.0 / (double) a[i].f;
}
sort(a + 1, a+ 1 + N);
for(int i = 1; i <= N ; i++){
if(a[i].f <= M){
res += a[i].j;
M -= a[i].f;
}else{
res += (double)M * 1.0 * a[i].x ;
break;
}
}
printf("%.3lf\n", res);
}
return 0;
}