Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define pb push_back
- int main()
- {
- int n;
- cin>>n;
- vector<vector<int>> va(n, vector<int> (3));
- for(auto &e: va)
- cin>>e[0]>>e[1]>>e[2];
- int wa=0, wb=0;
- vector<array<ll int, 2>> canGet;
- for(auto e: va)
- {
- int x = e[0];
- int y = e[1];
- int z = e[2];
- wa += (x > y) * z;
- wb += (x < y) * z;
- if(x < y) canGet.pb({z, (y-x)/2 + 1});
- }
- if(wa > wb) return cout<<"0\n", 0;
- vector<ll int> cost(100010, 1e18);
- cost[0] = 0;
- for(auto [z, c]: canGet)
- {
- for(int i=100010-z-1; i>=0; i--)
- cost[i+z] = min(cost[i+z], cost[i]+c);
- }
- ll int ans = 1e18;
- for(int i=0; i<100010; i++)
- {
- if(i+wa > wb-i)
- ans = min(ans, cost[i]);
- }
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment