fork download
  1. /*input
  2. 4 1
  3. 0 2
  4. 0 3
  5. 3 5
  6. 0 6
  7. */
  8. #include <bits/stdc++.h>
  9. #include<stdio.h>
  10. using namespace std;
  11. #define F(i,a,b) for(ll i = a; i <= b; i++)
  12. #define RF(i,a,b) for(ll i = a; i >= b; i--)
  13. #define pii pair<ll,ll>
  14. #define PI 3.14159265358979323846264338327950288
  15. #define ll long long
  16. #define ff first
  17. #define ss second
  18. #define pb(x) push_back(x)
  19. #define mp(x,y) make_pair(x,y)
  20. #define debug(x) cout << #x << " = " << x << endl
  21. #define INF 1000000009
  22. #define mod 1000000007
  23. #define S(x) scanf("%d",&x)
  24. #define S2(x,y) scanf("%d%d",&x,&y)
  25. #define P(x) printf("%d\n",x)
  26. #define all(v) v.begin(),v.end()
  27. ll BIT[200005];
  28. void update(ll id,ll val) {
  29. for(ll i=id;i<=200000;i+=i&-i) BIT[i]+=val;
  30. }
  31. ll query(ll id) {
  32. ll sum=0;
  33. for(ll i=id;i>0;i-=i&-i) sum+=BIT[i];
  34. return sum;
  35. }
  36. ll arr[200005];
  37. int main()
  38. {
  39. std::ios::sync_with_stdio(false);
  40. ll n,f;
  41. cin>>n>>f;
  42. ll ans = 0;
  43. F(i,0,n-1)
  44. {
  45. ll k,l;
  46. cin>>k>>l;
  47. ll in = min(k,l);
  48. ans = ans + min(k,l);
  49. k = 2ll*k;
  50. ll fin = min(k,l);
  51. arr[i] = fin - in;
  52. }
  53. sort(arr,arr+n);
  54. ll i=n-1;
  55. while(f--)
  56. {
  57. ans += arr[i];
  58. i--;
  59. }
  60. cout<<ans<<endl;
  61. return 0;
  62. }
Success #stdin #stdout 0s 18352KB
stdin
Standard input is empty
stdout
47412097835133