File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+
4+ long long int totalSweetness (vector<pair<int ,int >> a)
5+ {
6+ int n=a.size (),noOfBands=1 ;
7+ long long int ans=0 ;
8+
9+ sort (a.begin (),a.end ());
10+
11+ vector<int > uniqueSongs;
12+
13+ for (int i=0 ;i<n;i++)
14+ {
15+ if (i==0 || a[i].first !=a[i-1 ].first )
16+ {
17+ uniqueSongs.push_back (a[i].second );
18+ }
19+ else
20+ {
21+ ans+=a[i].second ;
22+ }
23+ }
24+ sort (uniqueSongs.begin (),uniqueSongs.end ());
25+
26+ ans=ans*uniqueSongs.size ();
27+
28+ for (int i=0 ;i<uniqueSongs.size ();i++)
29+ {
30+ ans=ans+uniqueSongs[i]*(long long )(i+1 );
31+ }
32+ return ans;
33+ }
34+ int main ()
35+ {
36+ int t;
37+ cin>>t;
38+ for (int i=1 ;i<=t;i++)
39+ {
40+ int n;
41+ cin>>n;
42+ vector<pair<int ,int >> a (n);
43+ for (int j=0 ;j<n;j++)
44+ {
45+ cin>>a[j].first >>a[j].second ;
46+ }
47+ long long int ans=totalSweetness (a);
48+ cout<<ans<<endl;
49+ }
50+ return 0 ;
51+ }
You can’t perform that action at this time.
0 commit comments