Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) 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,然后在从剩下的中
取最大的,直到满足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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值