Skip to content

Commit

Permalink
Create LEMUSIC.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanshiguptaaa authored Apr 1, 2021
1 parent 306a007 commit 7209b6b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Greedy/LEMUSIC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<bits/stdc++.h>
using namespace std;

long long int totalSweetness(vector<pair<int,int>> a)
{
int n=a.size(),noOfBands=1;
long long int ans=0;

sort(a.begin(),a.end());

vector<int> uniqueSongs;

for(int i=0;i<n;i++)
{
if(i==0 || a[i].first!=a[i-1].first)
{
uniqueSongs.push_back(a[i].second);
}
else
{
ans+=a[i].second;
}
}
sort(uniqueSongs.begin(),uniqueSongs.end());

ans=ans*uniqueSongs.size();

for(int i=0;i<uniqueSongs.size();i++)
{
ans=ans+uniqueSongs[i]*(long long)(i+1);
}
return ans;
}
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int n;
cin>>n;
vector<pair<int,int>> a(n);
for(int j=0;j<n;j++)
{
cin>>a[j].first>>a[j].second;
}
long long int ans=totalSweetness(a);
cout<<ans<<endl;
}
return 0;
}

0 comments on commit 7209b6b

Please sign in to comment.