-
Notifications
You must be signed in to change notification settings - Fork 67
/
ADAFRIEN.cpp
58 lines (50 loc) · 1.06 KB
/
ADAFRIEN.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// main.cpp
// practice
//
// Created by Mahmud on 10/12/17.
// Copyright © 2017 Mahmud. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <utility>
using namespace std;
const int MAX = 100005;
int N, K;
long long result = 0;
map<string, long long> m;
vector<long long> costs;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
while(cin >> N >> K) {
if (cin.eof()) {
break;
}
result = 0;
m.clear();
costs.clear();
for (int i = 0; i < N; i ++) {
string word;
int value;
cin >> word >> value;
m[word] += value;
}
for (auto i : m) {
costs.push_back(i.second);
}
sort(costs.begin(), costs.end(), greater<long long>());
for (auto i : costs) {
if (K > 0) {
result += i;
K --;
}
}
cout << result << endl;
}
return 0;
}