题解:CF1612E Messages
wenhaoran11 · · 题解
题解
我们假设
题意就变成了使
假设我们已经知道了
然后观察力惊人的你发现了
设
首先有
所以
并且
而最后那个东西显然是大于等于
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,k[N],m[N];
struct node{
int val,id;
};
node b[N];
struct nodee{
vector<int> mp;
double x;
void clear(){
x=0;
mp.clear();
}
};
nodee ans,tmp;
bool cmp(node x,node y){
return x.val>y.val;
}
signed main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld",&m[i],&k[i]);
}
for(int t=1;t<=20;t++){
for(int i=0;i<N;i++){
b[i]={0,i};
}
for(int i=1;i<=n;i++) b[m[i]].val+=min(t,k[i]);
sort(b+1,b+N,cmp);
tmp.clear();
for(int i=1;i<=t;i++){
tmp.x+=b[i].val;
tmp.mp.push_back(b[i].id);
}
tmp.x/=t;
if(tmp.x>ans.x) ans=tmp;
}
printf("%lld\n",(long long)ans.mp.size());
for(int i:ans.mp){
printf("%lld ",i);
}
return ~(-1);
}