Codeforces Round #128 (Div. 2) C. Photographer

本文探讨了摄影师如何通过合理分配相机内存资源,最大化服务客户数量的问题。通过使用贪心算法,按照客户所需内存总和递减排序,实现最优分配方案。
C. Photographer
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.

The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes amegabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.

Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.

Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.

Input

The first line contains two integers n and d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 ≤ a ≤ b ≤ 104) — the size of one low quality photo and of one high quality photo, correspondingly.

Next n lines describe the clients. The i-th line contains two integers xi and yi (0 ≤ xi, yi ≤ 105) — the number of low quality photos and high quality photos the i-th client wants, correspondingly.

All numbers on all lines are separated by single spaces.

Output

On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.

Sample test(s)
input
3 10
2 3
1 4
2 1
1 0
output
2
3 2 
input
3 6
6 6
1 1
1 0
1 0
output
1
2 

题意:有一个摄影师有一个相机,共有内存d,生产一张低质量的照片需要内存a,生产一张高质量的照片需要内存b,每个顾客都需要特定数量特定种类的照片,求最多可满足多少个顾客。第一行输入顾客的数量和照相机的内存,第二行输入低质量和高质量的相片分别需要的相机内存,接下来n行,输入每个顾客需要的低质量和高质量的相片数。求求最多可服务的顾客的数量。
思路:典型的贪心,按照每个顾客的所需相机内存总和递减排序,然后求最多可服务的顾客的数量。
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
 int n,d,aa,bb,i,j;
struct sa
{
    int a;
    int b;
    int num;
}s[100005];
bool cmp(sa x,sa y)
 {
     return x.a*aa+x.b*bb<y.a*aa+y.b*bb;
 }
 int main()
 {

  while(~scanf("%d%d",&n,&d))
   {
       scanf("%d%d",&aa,&bb);
      for(i=0;i<n;i++)
       {
           scanf("%d%d",&s[i].a,&s[i].b);
           s[i].num=i+1;
       }
     sort(s,s+n,cmp);
     int sum=0;
      for(i=0;i<n;i++)
       {
          if(d-s[i].a*aa-s[i].b*bb>=0)
          {
              d=d-s[i].a*aa-s[i].b*bb;
              sum++;
          }
       }
      if(sum==0){printf("0\n");continue;}
     printf("%d\n%d",sum,s[0].num);
     for(i=1;i<sum;i++)
       printf(" %d",s[i].num);
     cout<<endl;
   }
     return 0;
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值