2. Range Selection
bool ok(vector<ll> starts,ll d,ll m){
ll st=starts[0]+m;
for(int i=1;i<starts.size();i++){
st=max(st,starts[i]);
if(starts[i]+d<st) return false;
st+=m;
}
return true;
}
ll solve(vector<ll> &starts,ll d){
sort(starts.begin(),starts.end());
ll l=0,r=1e15;
while(l<=r){
ll m=(l+r)/2;
if(ok(starts,d,m)){
l=m+1;
}else r=m-1;
}
return r;
}
1. GetMinRemoval
string s;
cin>>s;
int k;
cin>>k;
vector<int> freq(26);
for(int i=0;i<s.size();i++) {
freq[s[i]-'a']++;
}
sort(freq.begin(),freq.end());
int i=0,j=freq.size()-1;
int ans = 0;
while(i<=j) {
if(freq[i]==0) i++;
else if(freq[j]==0) j--;
else if(abs(freq[i]-freq[j])>k) {
ans += abs(freq[i]-freq[j])-k;
j--;
} else break;
}
cout<<ans<<endl;