Guest User

Untitled

a guest
Jun 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. bool sortWay(const pair<unsigned long long,unsigned long long> &a,
  5. const pair<unsigned long long,unsigned long long> &b)
  6. {
  7. return (min(a.first * 2, a.second) - a.first > min(b.first * 2, b.second) - b.first);
  8. }
  9. int main()
  10. {
  11. unsigned long long n, f, k, l, sum = 0;
  12. vector<pair<unsigned long long, unsigned long long> > v;
  13. cin >> n >> f;
  14. while(n--){
  15. cin >> k >> l;
  16. v.push_back(make_pair(k, l));
  17. sum += min(k, l);
  18. }
  19. sort(v.begin(), v.end(), sortWay);
  20. for(int i = 0; i < f; i++){
  21. unsigned long long first = v[i].first, second = v[i].second;
  22. sum += min(first * 2, l) - first;
  23. }
  24. cout << sum << endl;
  25. return 0;
  26. }
Add Comment
Please, Sign In to add comment