Ankit_132

D

Aug 27th, 2023
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     int n;
  13.     cin>>n;
  14.  
  15.     vector<vector<int>> va(n, vector<int> (3));
  16.     for(auto &e: va)
  17.       cin>>e[0]>>e[1]>>e[2];
  18.  
  19.     int wa=0, wb=0;
  20.  
  21.     vector<array<ll int, 2>> canGet;
  22.  
  23.     for(auto e: va)
  24.     {
  25.         int x = e[0];
  26.         int y = e[1];
  27.         int z = e[2];
  28.  
  29.         wa += (x > y) * z;
  30.         wb += (x < y) * z;
  31.  
  32.         if(x < y)       canGet.pb({z, (y-x)/2 + 1});
  33.     }
  34.  
  35.     if(wa > wb)     return cout<<"0\n", 0;
  36.  
  37.     vector<ll int> cost(100010, 1e18);
  38.  
  39.     cost[0] = 0;
  40.  
  41.     for(auto [z, c]: canGet)
  42.     {
  43.         for(int i=100010-z-1; i>=0; i--)
  44.             cost[i+z] = min(cost[i+z], cost[i]+c);
  45.     }
  46.  
  47.     ll int ans = 1e18;
  48.  
  49.     for(int i=0; i<100010; i++)
  50.     {
  51.         if(i+wa > wb-i)
  52.             ans = min(ans, cost[i]);
  53.     }
  54.  
  55.     cout<<ans<<"\n";
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment