Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iomanip>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <cctype>
  8. #include <cstring>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <deque>
  13. #include <stack>
  14. #include <map>
  15. #include <set>
  16. #include <algorithm>
  17. #include <iterator>
  18. #include <bitset>
  19. #include <ctime>
  20. using namespace std;
  21.  
  22. #define FOR(i,a,b) for (int i = (a); i < (b); i++)
  23. #define rep(i,n) FOR(i,0,n)
  24. #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
  25. #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
  26. #define FILL(a,value) memset(a, value, sizeof(a))
  27.  
  28. #define SZ(a) (int)a.size()
  29. #define ALL(a) a.begin(), a.end()
  30. #define PB push_back
  31. #define MP make_pair
  32.  
  33. typedef long long LL;
  34. typedef vector<int> VI;
  35. typedef vector<LL>VL;
  36. typedef pair<int, int> PII;
  37. typedef pair<double, double> PDD;
  38.  
  39. const double PI = acos(-1.0);
  40. const int INF = 1000 * 1000 * 1000 + 7;
  41. const LL LINF = LL(1e18);
  42. const LL MAS = 1e6;
  43. const double EPS = 1e-7;
  44. const LL MAX = 4294967296;
  45.  
  46. int main()
  47. {
  48. int n,m;
  49. cin >> n >> m;
  50. vector < vector<LL > > g(m) ;
  51. vector <vector < LL > > g1(m ) ;
  52. rep(i,n)
  53. {
  54. int x,y;
  55. cin >> x >> y ;
  56. --x ;
  57. g1[x].PB(y);
  58. }
  59. rep(i,m)
  60. {
  61. sort(g1[i].begin(),g1[i].end()) ;
  62. reverse(g1[i].begin(),g1[i].end());
  63.  
  64. }
  65. rep(i,m)
  66. {
  67. LL sum = 0;
  68. rep(j,g1[i].size())
  69. {
  70. sum+=g1[i][j];
  71. g[i].PB(sum) ;
  72. }
  73. }
  74. LL mxcount = 0;
  75. rep(j,m )
  76. {
  77. LL v =g[j].size() ;
  78. mxcount = max(v,mxcount) ;
  79. }
  80. LL cur = 0;
  81. LL mx = 0 ;
  82. rep(j,mxcount)
  83. {
  84. rep(i,m )
  85. {
  86. if ( g[i].size() >= j+1)
  87. {
  88. cur+=g[i][j] ;
  89. }
  90. }
  91. mx =max(mx,cur) ;
  92. cur = 0;
  93. }
  94. cout << mx ;
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement