Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <iomanip>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cctype>
- #include <cstring>
- #include <vector>
- #include <list>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <iterator>
- #include <bitset>
- #include <ctime>
- using namespace std;
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define rep(i,n) FOR(i,0,n)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef vector<LL>VL;
- typedef pair<int, int> PII;
- typedef pair<double, double> PDD;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = LL(1e18);
- const LL MAS = 1e6;
- const double EPS = 1e-7;
- const LL MAX = 4294967296;
- int main()
- {
- int n,m;
- cin >> n >> m;
- vector < vector<LL > > g(m) ;
- vector <vector < LL > > g1(m ) ;
- rep(i,n)
- {
- int x,y;
- cin >> x >> y ;
- --x ;
- g1[x].PB(y);
- }
- rep(i,m)
- {
- sort(g1[i].begin(),g1[i].end()) ;
- reverse(g1[i].begin(),g1[i].end());
- }
- rep(i,m)
- {
- LL sum = 0;
- rep(j,g1[i].size())
- {
- sum+=g1[i][j];
- g[i].PB(sum) ;
- }
- }
- LL mxcount = 0;
- rep(j,m )
- {
- LL v =g[j].size() ;
- mxcount = max(v,mxcount) ;
- }
- LL cur = 0;
- LL mx = 0 ;
- rep(j,mxcount)
- {
- rep(i,m )
- {
- if ( g[i].size() >= j+1)
- {
- cur+=g[i][j] ;
- }
- }
- mx =max(mx,cur) ;
- cur = 0;
- }
- cout << mx ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement