fork download
  1. //----->|try=0; while(!success) try++;|<------
  2. //----->|Belief Yourself,Respect Yourself|<----
  3. //----->|Be Proud Of Yourself,You're Doing Your best|<-----
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define uniq(x) x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
  7. #define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr //Upper value search;
  8. #define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr //Lower value search;
  9. #define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
  10. #define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
  11. #define rep(i, n) for(int i = 0; i < n; ++i)
  12. #define REP(i, n) for(int i = 1; i <= n; ++i)
  13. #define PI acos(-1.0)//PI Calculation
  14. #define LL long long
  15. #define AND(a,b) ((a) & (b))
  16. #define OR(a,b) ((a)|(b))
  17. #define XOR(a,b) ((a) ^ (b))
  18. #define mp make_pair
  19. #define sqr(x) ((x)*(x))
  20. #define sqrt(x) sqrt(1.0*(x))
  21. #define INF_MAX 2147483647
  22. #define INF_MIN -2147483647
  23. #define MX 1000005
  24. #define MOD 1000000007
  25. template<typename T> T POW(T b,T p) //Pow calculation
  26. {
  27. T r=1;
  28. while(p)
  29. {
  30. if(p&1)r=(r*b);
  31. b=(b*b);
  32. p>>=1;
  33. }
  34. return r;
  35. }
  36.  
  37. template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
  38. {
  39. T r=1;
  40. while(p)
  41. {
  42. if(p&1)r=(r*b)%m;
  43. b=(b*b)%m;
  44. p>>=1;
  45. }
  46. return r;
  47. }
  48.  
  49. //||--------------------------->||Main_Code_Start_Here||<---------------------------------||
  50. int main()
  51. {
  52. //freopen("a.in", "r", stdin);
  53. //freopen("a.out", "w", stdout);
  54. int n,k,p,d;
  55. LL res;
  56. LL t;
  57. while(cin>>n>>k)
  58. {
  59. LL res=0;
  60. priority_queue<LL>Q;
  61. rep(i,n)
  62. {
  63. cin>>p>>d;
  64. res+=p;
  65. Q.push(-p-d);
  66. }
  67. while(Q.size()>k)
  68. {
  69. res+=Q.top();
  70. Q.pop();
  71. }
  72. cout<<max(0LL,res)<<endl;
  73. }
  74. }
  75.  
Success #stdin #stdout 0s 3476KB
stdin
2 1
10 5
3 1
stdout
9