忘记二分最小值 一直寄
参考了题目链接 晚点补文字
#include<bits/stdc++.h>
#define mst(s,x) memset(s,x,sizeof(s));
#define sr(x) scanf("%lld",&x);
#define sr2(a,b) scanf("%d%d",&a,&b);
#define sr3(a,b,c) scanf("%d%d%d",&a,&b,&c);
#define f(i,a,n) for(int i=a;i<=n;i++)
#define sc(x) cout<<#x<<" : "<<x<<endl;
#define hh cout<<endl;
#define pii pair<int,int>
#define pb(x) push_back(x)
#define mk(a,b) make_pair(a,b)
#define ls(x) x<<1
#define rs(x) x<<1|1
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define ll __int128
using namespace std;
inline ll read()
{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') x=(x<<1)+(x<<3)+c-'0',c=getchar();
return w==1?x:-x;
}
inline void write(ll x)
{
if(x>=10) write(x/10);
putchar(x%10+'0');
}
#define int long long
#define dd double
const int N=2e5+5;
vector<pii>v;
vector<int>ans;
int sum[N];
int n,p,q,m;
int vis[N];
bool ok(int maxn,int Sum)
{
return q*maxn*m<=p*Sum;
}
bool check(int mid)
{
for(int i=mid;i<=n;i++)
{
if(q*v[i-1].fi*mid<=p*(sum[i]-sum[i-mid])) return true;
}
return false;
}
inline void solve()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
int A;
scanf("%lld",&A);
v.push_back({A,i});
}
scanf("%lld%lld",&p,&q);
sort(v.begin(),v.end(),[&](pii a,pii b)
{
return a.fi<b.fi;
});
for(int i=0;i<n;i++)
{
sum[i+1]=v[i].fi+sum[i];
}
int l=1,r=n;
while(l<r)
{
int mid=(r+l)>>1;
if(check(mid))l=mid+1;
else r=mid;
}
m=l-1;
for(int i=m;i<=n;i++)
{
if(!ok(v[i-1].fi,sum[i]-sum[i-m])) continue;
int l=1,r=i-m+1,Sum=sum[i]-sum[i-m+1];
while(l<r)
{
int mid=(r+l)>>1;
if(ok(v[i-1].fi,Sum+v[mid-1].fi)) r=mid;
else l=mid+1;
}
vis[l]+=1,vis[i+1]-=1;
}
for(int i=1;i<=n;i++)vis[i]+=vis[i-1];
for(int i=1;i<=n;i++)if(!vis[i])ans.push_back(v[i-1].se);
cout<<ans.size()<<endl;
sort(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++)
{
printf("%lld%s",ans[i],(i==n)?"":" ");
}
}
signed main()
{
clock_t c1=clock();
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
int T=1;
for(int i=1;i<=T;i++)
{
solve();
}
end:
cerr<< endl << "Time used:" << clock() - c1 << endl;
return 0;
}
|