-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2036B.cpp
More file actions
42 lines (33 loc) · 740 Bytes
/
2036B.cpp
File metadata and controls
42 lines (33 loc) · 740 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>
using namespace std;
void solve(){
int m, b; cin >> m >> b;
map<int, int> m1;
for(int i = 0; i < b; i++){
int val1, val2; cin >> val1 >> val2;
if(m1[val1]){
m1[val1] += val2;
}
else{
m1[val1] = val2;
}
}
vector <int> v1;
for(auto &i : m1){
v1.push_back(i.second);
}
sort(v1.begin(), v1.end(), greater<int>());
int sum = 0;
for(int i = 0; i < m && i < v1.size(); i++){
sum += v1[i];
}
cout << sum << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while(t--){
solve();
}
}