Codeforces 967 D. Resource Distribution

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

CodeForces - 616D是一个关于找到一个序列中最长的第k好子段的起始位置和结束位置的问题。给定一个长度为n的序列和一个整数k,需要找到一个子段,该子段中不超过k个不同的数字。题目要求输出这个序列最长的第k好子段的起始位置和终止位置。 解决这个问题的方法有两种。第一种方法是使用尺取算法,通过维护一个滑动窗口来记录\[l,r\]中不同数的个数。每次如果这个数小于k,就将r向右移动一位;如果已经大于k,则将l向右移动一位,直到个数不大于k。每次更新完r之后,判断r-l+1是否比已有答案更优来更新答案。这种方法的时间复杂度为O(n)。 第二种方法是使用枚举r和双指针的方法。通过维护一个最小的l,满足\[l,r\]最多只有k种数。使用一个map来判断数的种类。遍历序列,如果当前数字在map中不存在,则将种类数sum加一;如果sum大于k,则将l向右移动一位,直到sum不大于k。每次更新完r之后,判断i-l+1是否大于等于y-x+1来更新答案。这种方法的时间复杂度为O(n)。 以上是两种解决CodeForces - 616D问题的方法。具体的代码实现可以参考引用\[1\]和引用\[2\]中的代码。 #### 引用[.reference_title] - *1* [CodeForces 616 D. Longest k-Good Segment(尺取)](https://blog.csdn.net/V5ZSQ/article/details/50750827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces616 D. Longest k-Good Segment(双指针+map)](https://blog.csdn.net/weixin_44178736/article/details/114328999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值