1011B - Planning The Expedition - CodeForces Solution


binary search brute force implementation *1200

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<class T>
bool ckmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }

typedef long long ll;
bool check(int mid, map<int, int>&freq, int n){
    if(mid==0) return false;
    int cnt=0;
    for(auto p:freq)
        cnt+=(p.second/mid);
    return cnt>=n;
}
void TT() {
    int n, m;
    cin>>n>>m;
    map<int, int>freq;
    for(int i=0;i<m;i++){
        int type;
        cin>>type;
        freq[type]++;
    }
    int st=0, e=100, mid, ans=0;
    while(st<=e){
        mid=(st+e+1)/2;
        if(check(mid, freq, n)){
            st=mid+1;
            ans=mid;
        }
        else e=mid-1;
    }
    cout<<ans<<'\n';
}
int main() {
    FAST
    int testCases = 1;
//    cin >> testCases;
    while (testCases--) TT();
    return 0;
}

 	 					     						 						  	 	


Comments

Submit
0 Comments
More Questions

1734E - Rectangular Congruence
1312D - Count the Arrays
424C - Magic Formulas
1730C - Minimum Notation
1730B - Meeting on the Line
1730A - Planets
302B - Eugeny and Play List
1730D - Prefixes and Suffixes
1515C - Phoenix and Towers
998A - Balloons
1734F - Zeros and Ones
1144B - Parity Alternated Deletions
92B - Binary Number
1144C - Two Shuffled Sequences
1154B - Make Them Equal
1272B - Snow Walking Robot
522B - Photo to Remember
608B - Hamming Distance Sum
1408F - Two Different
274B - Zero Tree
1726H - Mainak and the Bleeding Polygon
722A - Broken Clock
129B - Students and Shoelaces
697B - Barnicle
903D - Almost Difference
1443B - Saving the City
1215C - Swap Letters
1251C - Minimize The Integer
1494B - Berland Crossword
295A - Greg and Array