fork download
  1. /*
  2.  ID: bradyawn
  3.  PROG: contest
  4.  LANG: C++11
  5.  */
  6.  
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <iomanip>
  10. #include <fstream>
  11. #include <vector>
  12. #include <deque>
  13. #include <string>
  14. #include <cmath>
  15. #include <map>
  16. #include <unordered_map>
  17. #include <utility>
  18. #include <set>
  19. #include <unordered_set>
  20. #include <ctime>
  21. #include <queue>
  22. #include <stack>
  23. #include <bitset>
  24. #include <random>
  25. #include <cstring>
  26. #include <functional>
  27.  
  28. using namespace std;
  29.  
  30. typedef long long ll;
  31. typedef pair<int,int> i2;
  32. typedef pair<ll,ll> ll2;
  33.  
  34. int dp[250001]; //maximize talent
  35.  
  36. int w[251];
  37. int t[251];
  38.  
  39. int n, wReq;
  40.  
  41. int main()
  42. {
  43. //ifstream inf("talent.in");
  44. //ofstream outf("talent.out");
  45. //outf << setprecision(10);
  46. // ios_base::sync_with_stdio(0); inf.tie(0);
  47.  
  48. cin >> n >> wReq;
  49.  
  50. int mxTalent = 0;
  51.  
  52. for (int i = 1; i <= n; i++)
  53. {
  54. cin >> w[i] >> t[i];
  55. mxTalent += t[i];
  56. }
  57.  
  58. for (int i = 1; i <= 250000; i++) dp[i] = 1e9;
  59.  
  60. for (int i = 1; i <= n; i++) //considering item i
  61. {
  62. for (int j = mxTalent; j >= 0; j--) //knapsack talent j
  63. if (j - t[i] >= 0) dp[j] = min(dp[j], dp[j-t[i]] + w[i]);
  64. }
  65.  
  66. int ans = 0;
  67.  
  68. for (int i = 1; i <= mxTalent; i++)
  69. if (dp[i] >= wReq) ans = max(ans, int(1000.0*i/dp[i]));
  70.  
  71. cout << ans << '\n';
  72.  
  73. return 0;
  74.  
  75. }
Success #stdin #stdout 0s 4440KB
stdin
5 7
5 100
2 20
2 20
2 20
2 20
stdout
17142