One department of some software company has nn servers of different specifications. Servers are indexed with consecutive integers from 11to nn. Suppose that the specifications of the jj-th server may be expressed with a single integer number cjcj of artificial resource units.
In order for production to work, it is needed to deploy two services S1S1 and S2S2 to process incoming requests using the servers of the department. Processing of incoming requests of service SiSi takes xixi resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service SiSi is deployed using kiki servers, then the load is divided equally between these servers and each server requires only xi/kixi/ki (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
The first line contains three integers nn, x1x1, x2x2 (2≤n≤3000002≤n≤300000, 1≤x1,x2≤1091≤x1,x2≤109) — the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains nn space-separated integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤1091≤ci≤109) — the number of resource units provided by each of the servers.
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k1k1 and k2k2 (1≤k1,k2≤n1≤k1,k2≤n) — the number of servers used for each of the services.
In the third line print k1k1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k2k2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
6 8 16 3 5 2 9 8 7
Yes 3 2 1 2 6 5 4
4 20 32 21 11 11 12
Yes 1 3 1 2 3 4
4 11 32 5 5 16 16
No
5 12 20 7 8 4 11 9
No
In the first sample test each of the servers 1, 2 and 6 will will provide 8/3=2.(6)8/3=2.(6) resource units and each of the servers 5, 4 will provide 16/2=816/2=8 resource units.
In the second sample test the first server will provide 2020 resource units and each of the remaining servers will provide 32/3=10.(6)32/3=10.(6)resource units.
题解:
因为连续取一定是最优解,并且先取大的一定是最优解。
因此可以从大的开始取,取到满足x1,然后在从剩下的中
取最大的,直到满足x2。若没有找到可行解,则反过来,
先取到满足x2,在取满足x1。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=300005;
struct node
{
ll x;
int id;
} c[maxn];
bool cmp(const node &a,const node &b)
{
return a.x>b.x;
}
int main()
{
int n;
ll x1,x2;
scanf("%d%lld%lld",&n,&x1,&x2);
for(int i=1; i<=n; i++)
{
scanf("%lld",&c[i].x);
c[i].id=i;
}
sort(c+1,c+n+1,cmp);
int bb=0;
for(ll i=1; i<n; i++)
{
if(x1<=c[i].x*i)
{
for(ll j=i+1; j<=n; j++)
{
if(x2<=c[j].x*(j-i))
{
bb=1;
printf("Yes\n");
printf("%lld %lld\n",i,j-i);
for(int k=1; k<=i; k++)
{
printf("%d",c[k].id);
if(k!=i)
printf(" ");
else
printf("\n");
}
for(int k=i+1; k<=j; k++)
{
printf("%d",c[k].id);
if(k!=j)
printf(" ");
else
printf("\n");
}
break;
}
}
break;
}
}
if(!bb)
{
swap(x1,x2);
for(ll i=1; i<n; i++)
{
if(x1<=c[i].x*i)
{
for(ll j=i+1; j<=n; j++)
{
if(x2<=c[j].x*(j-i))
{
bb=1;
printf("Yes\n");
printf("%lld %lld\n",j-i,i);
for(int k=i+1; k<=j; k++)
{
printf("%d",c[k].id);
if(k!=j)
printf(" ");
else
printf("\n");
}
for(int k=1; k<=i; k++)
{
printf("%d",c[k].id);
if(k!=i)
printf(" ");
else
printf("\n");
}
break;
}
}
break;
}
}
}
if(!bb)printf("No\n");
return 0;
}