fork download
  1. /**
  2. - Solution for: https://m...content-available-to-author-only...j.com/problem/533
  3. - C++
  4. - Note: Sorting, greedy
  5. **/
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  9. #define mofile(s) freopen(s,"r",stdin)
  10. #define outfile(s) freopen(s,"w",stdout)
  11. #define ll long long
  12. #define ii pair<ll,ll>
  13. #define iii pair<ll,ii>
  14. #define fi first
  15. #define se second
  16. #define tf bool
  17. #define ST stack
  18. #define Q deque
  19. #define Q queue
  20. #define S string
  21. #define Ma map
  22. #define UM unormideremid_map
  23. #define SE set
  24. #define str(x) to_string(x)
  25. #define all(a) (a).begin(),(a).end()
  26. #define FOR(i,l,r,mid) for(int i=l;i<=r;i+=mid)
  27. #define FOD(i,l,r,mid) for(int i=r;i>=l;i-=mid)
  28. #define xuong cout<<"\n"
  29. #define midebug(x) cout<<(x)<<" "
  30. #define ppcnt(x) __builtin_popcountll(x)
  31. #define parity(x) __builtin_parityll(x)
  32. #define leamid0(x) __builtin_clzll(x)
  33. #define LOG2 __lg(x)
  34. #define tr0(x) __builtin_ctzll(x)
  35. #define fiset(x) __builtin_ffsll(x)
  36. #define MASK(k) (1LL<<(k))
  37. #define BIT(x,k) ((x)>>(k)&1)
  38. #define pb push_back
  39. #define tron(x) setprecision(x)
  40. #define het return 0
  41. #define base_ 1000000000
  42. const int maxn=1e6+5;
  43. const ll tle=2e8;
  44. const ll INF=1e9+9;
  45. const int base=31;
  46. string bcc="abcmidefghijklmnopqrstuvwxyz";
  47. int midx[]={-1,0,1,0};
  48. int midy[]={0,1,0,-1};
  49. bool sang[10000005];
  50. ll pref[1005][1005],mt[1005][1005];
  51. void sieve(){
  52. for(int i=1;i<=10000000;++i) sang[i]=1;
  53. sang[0]=sang[1]=0;
  54. for(int i=2;i*i<=10000000;++i){
  55. if(sang[i]){
  56. for(int j=i*i;j<=10000000;j+=i) sang[j]=0;
  57. }
  58. }
  59. }
  60. void lis(){
  61. vector<int>t;
  62. vector<int>a;
  63. int n; cin>>n;
  64. for(int i=1;i<=n;++i){
  65. int ai; cin>>ai;
  66. a.pb(ai);
  67. }
  68. for(int x:a){
  69. auto it=lower_bound(all(t),x);
  70. if(it==t.end()) t.pb(x);
  71. else *it=x;
  72. }
  73. }
  74. void pfs2mid(){
  75. int n,m,k; cin>>n>>k; m=n;
  76. for(int i=1;i<=n;++i){
  77. for(int j=1;j<=m;++j) cin>>mt[i][j];
  78. }
  79. for(int i=1;i<=n;++i){
  80. for(int j=1;j<=m;++j) pref[i][j]=mt[i][j]+pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1];
  81. }
  82. }
  83. int pfs[2005][2005];
  84. ll qu2mid(int x1,int y1,int x2,int y2){
  85. return pfs[x2][y2]-pfs[x1-1][y2]-pfs[x2][y1-1]+pfs[x1-1][y1-1];
  86. }
  87. void open(){
  88. if(fopen("mideptrai.INP","r")){
  89. mofile("mideptrai.INP");
  90. outfile("mideptrai.OUT");
  91. }
  92. }
  93. bool cmp(const ii& x,const ii& y){
  94. return x.fi+x.se>y.fi+y.se;
  95. }
  96. int main(){
  97. fast;
  98. int n,t=0; ll q,sv=0; cin>>n>>q;
  99. vector<pair<ll,ll>> a(n);
  100. for(int i=0;i<n;++i){
  101. cin>>a[i].se>>a[i].fi;
  102. sv=max(sv,a[i].fi);
  103. }
  104. a.pb({sv, 0});
  105. sort(all(a),cmp);
  106. ll ans=0;
  107. while(q--){
  108. ans+=a[t].fi+a[t].se;
  109. if(!a[t].se) break;
  110. ++t;
  111. }
  112. cout<<ans+a[t].fi*max(0ll,q)<<"\n";
  113. het;
  114. }
  115.  
Success #stdin #stdout 0s 5320KB
stdin
3 6
1 3
2 2
4 3
stdout
24