1077E - Thematic Contests - CodeForces Solution


greedy sortings *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define fr                first
#define sc                second
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define debug(x)  cout<<(x)<<'\n';


const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;


void solve(){
   

int n;
cin>>n;
int a[n];
rep(i,0,n) cin>>a[i];
map<int,int> m;
for(int i=0;i<n;i++)
m[a[i]]++;

vector<int> v;
for(auto it=m.begin();it!=m.end();it++)
v.pb(it->sc);

sort(all(v));
int ans=0;
for(int i=1;i<=n;i++)
{

int curr=i;
int  temp=0;
int j=0;
for(;j!=v.size();)
{

auto it=lower_bound(v.begin()+j,v.end(),curr);
if(it==v.end()) {
    break;
}
temp+=curr;
curr=curr*2;
j=it-v.begin()+1;

}


ans=max(ans,temp);

}
cout<<ans<<'\n';
    
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int t=1;

    while(t--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted