Rentib

domek z kart na 40 pkt zachłannie

Apr 29th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, k, s = 0, curr = 0;
  5. cin >> n >> k;
  6. k /= 2;
  7. vector<int> G;
  8. G.push_back(0);
  9. for(int i = 0;i < n;i++)
  10. for(int j = 0, a, b;j < 1 << i;j++){
  11. cin >> a >> b;
  12. G.push_back(a + b);
  13. }
  14. priority_queue<pair<int, int> > opcje;
  15. opcje.push(make_pair(G[1], 1));
  16. while(k--){
  17. pair<int, int> v = opcje.top();
  18. curr += v.first;
  19. opcje.pop();
  20. if(v.second < 1 << (n-1)){
  21. opcje.push(make_pair(G[v.second * 2], v.second * 2));
  22. opcje.push(make_pair(G[v.second * 2 + 1], v.second * 2 + 1));
  23. }
  24. s = max(s, curr);
  25. }
  26. cout << s;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment