SHARE
    TWEET
    Vince14

    Talent Show

    Mar 11th, 2023
    157
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    C++ 1.65 KB | Source Code | 0 0
    1. #include <iostream>
    2. #include <string>
    3. #include <cstring>
    4. #include <algorithm>
    5. #include <cmath>
    6. #include <vector>
    7. #include <set>
    8. #include <map>
    9. #include <stack>
    10. #include <queue>
    11. #include <deque>
    12. #include <unordered_map>
    13. #include <numeric>
    14. #include <iomanip>
    15. #include <regex>
    16. using namespace std;
    17. #define pii pair<long long , long long>
    18. #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
    19. const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    20. const long long dl[2] = {1, -1};
    21. const long long MOD = 1e9 + 7;
    22. const long long MAX = 255;
    23. long long n, w;
    24. long long weight[MAX], talent[MAX];
    25. long long dp[1005];
    26. bool check(long long cur){
    27. for(long long i = 0; i <= w; i++){
    28. dp[i] = -2e9;
    29. }
    30. dp[0] = 0;
    31. for(long long i = 0; i < n; i++){
    32. long long tmp = 1000 * talent[i] - cur * weight[i];
    33. for(long long j = w; j >= 0; j--){
    34. if(dp[j] == -2e9){
    35. continue;
    36. }
    37. if(dp[min(w, j + weight[i])] < dp[j] + tmp){
    38. dp[min(w, j + weight[i])] = dp[j] + tmp;
    39. }
    40. }
    41. }
    42. if(dp[w] >= 0){
    43. return true;
    44. }
    45. else{
    46. return false;
    47. }
    48. }
    49. int main() {
    50. freopen("talent.in", "r", stdin);
    51. freopen("talent.out", "w", stdout);
    52. FAST;
    53. cin >> n >> w;
    54. for(long long i = 0; i < n; i++){
    55. cin >> weight[i] >> talent[i];
    56. }
    57. long long lo = 0, hi = 250000001;
    58. while(lo < hi){
    59. long long mid = (lo + hi) / 2 + 1;
    60. if(check(mid)){
    61. lo = mid;
    62. }
    63. else{
    64. hi = mid - 1;
    65. }
    66. }
    67. cout << lo << "\n";
    68. }
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /