Advertisement
Guest User

Untitled

a guest
Aug 8th, 2021
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. long long n,f;
  7. cin >> n >> f;
  8. vector<pair<long long,long long>> v;
  9. for(long long i=0;i<n;i++)
  10. {
  11. long long a,b;
  12. cin >> a >> b;
  13. v.push_back(make_pair(a,b));
  14. }
  15. sort(v.begin(),v.end());
  16. for(long long i=n-1;i>=0;i--)
  17. {
  18. if(f>0 and v[i].second>0)
  19. {
  20. v[i].first*=2;
  21. f--;
  22. }
  23. }
  24. long long count=0;
  25. for(long long i=0;i<n;i++)
  26. {
  27. count+=min(v[i].first,v[i].second);
  28. }
  29. cout << count;
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement