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分配n个,为a1,a2,a3,a4……(表示下标,而且a1<a2<a3<a4……),X2分配m个,为b1,b2,……(意义相同)。那么假设an>bm,必有n+m<=an(取等号时1到an全部被分配任务),那么调整a让X1重新分配给an-n+1~an,调整b让X2重新分配给1~m,这样的调整方式必定存在,而且得到了一个新的解法。
那么我们就只需要判断这种新的解法是否可以存在,我们可以从小到大枚举n的大小,然后找到最大的对应的an(二分查找或者扫描指针),然后再在1~an-n中看是否存在t让m=t使得满足题意(这里的“是否存在”可以用预处理前缀bool量的办法O(1)判断)
注意这样做的假设建立在an>bm的基础上,如果an<bm怎么办呢,其实没关系,反着再来尝试一遍不久OK了吗?
代码太丑还是不放了,另外自己debug的能力还要加强,一些小错误太致命了,导致我赛场上没有写出这道题。