fork download
  1. #include <cstdio>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. struct room
  6. {
  7. int j, f;
  8. bool operator < (const room t) const {
  9. return (double) j/f >(double)t.j /t.f;
  10. }
  11. };
  12. int main()
  13. {
  14. int m, n, i;
  15. while(scanf("%d%d", &m, &n) && (m+1) ||(n+1))
  16. {
  17. vector<room> v;
  18. room r;
  19. double ans = 0;
  20. for(i=0; i<n; ++i)
  21. {
  22. scanf("%d%d",&r.j,&r.f);
  23. v.push_back(r);
  24. }
  25. sort(v.begin(), v.end());
  26. i = 0;
  27. while(m >0 && i<v.size())
  28. {
  29.  
  30. if(v[i].f <= m)
  31. {
  32. m -= v[i].f;
  33. ans += v[i].j;
  34. }else
  35. {
  36. ans +=(double)m /v[i].f *v[i].j;
  37. m = 0;
  38. }
  39. ++i;
  40. }
  41. printf("%.3lf\n",ans);
  42. }
  43. return 0;
  44. }
Time limit exceeded #stdin #stdout 5s 134528KB
stdin
Standard input is empty
stdout
Standard output is empty