-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathc.cc
More file actions
28 lines (28 loc) · 633 Bytes
/
c.cc
File metadata and controls
28 lines (28 loc) · 633 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// https://codeforces.com/contest/1082/problem/C
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
int main(){
ll n,m,s,r;
cin>>n>>m;
vvi a(m);
for(int i=0;i<n;i++){
cin>>s>>r;
s--;
a[s].push_back(r);
}
for(int i=0;i<m;i++){
sort(a[i].rbegin(),a[i].rend());
for(int j=1;j<a[i].size();j++)a[i][j]+=a[i][j-1];
}
sort(a.begin(),a.end(),[&](vi &u, vi &v){return u.size()>v.size();});
ll M=0;
for(int i=1;i<=a[0].size();i++){
ll c=0;
for(int j=0;j<m&&a[j].size()>=i;j++)c+=max(0,a[j][i-1]);
M=max(M,c);
}
cout<<M<<endl;
}