-
Notifications
You must be signed in to change notification settings - Fork 1
/
ADAFRIEN.cpp
78 lines (70 loc) · 1.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ADAFRIEN - Ada and Friends
// Author: Tarun Kumar
// E-mail: [email protected]
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INOUT freopen(name".inp","r", stdin); freopen(name".out","w",stdout);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fab(i,a,b) for(i=a;i<=b;i++)
#define f0r(i,n) for(i=n-1;i>=0;i--)
#define f1r(i,n) for(i=n;i>=1;i--)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define memo(a,b) memset(a,b,sizeof(a))
#define hi cout<<"hi\n";
#define ln "\n"
using namespace std;
const ld pi=acos(-1);
const ll mod=1e9+7;
const ll MAX=INT_MAX;
const ll MIN=INT_MIN;
bool sortbysec(pair<ll,ll> a,pair<ll,ll> b)
{
return (a.second<b.second);
}
int main()
{
FAST;
ll t,n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos;
string s;
char ch;
unordered_map <string,ll> m;
cin>>n>>k;
f0(i,n)
{
cin>>s>>x;
m[s]+=x;
}
vll v;
for(auto it: m)
{
v.pb(it.second);
// cout<<it.second<<" ";
}
sort(all(v));
p=0;
f0r(i,v.size())
{
if(!k)
break;
k--;
// cout<<v[i]<<" ";
p+=v[i];
}
cout<<p;
return 0;
}