Codeforces 967 D. Resource Distribution

本文探讨了一个软件公司的部门如何合理分配不同规格的服务器资源以运行两个服务的问题。通过贪心算法和排序策略,寻找可行的解决方案,并确保每个服务的运行效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D. Resource Distribution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains three integers nnx1x1x2x2 (2n3000002≤n≤3000001x1,x21091≤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 (1ci1091≤ci≤109) — the number of resource units provided by each of the servers.

Output

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 (1k1,k2n1≤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.

Examples
input
Copy
6 8 16
3 5 2 9 8 7
output
Copy
Yes
3 2
1 2 6
5 4
input
Copy
4 20 32
21 11 11 12
output
Copy
Yes
1 3
1
2 3 4
input
Copy
4 11 32
5 5 16 16
output
Copy
No
input
Copy
5 12 20
7 8 4 11 9
output
Copy
No
Note

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的能力还要加强,一些小错误太致命了,导致我赛场上没有写出这道题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值