A. Amr and Music

来源:互联网 发布:java调用ffmpeg命令行 编辑:程序博客网 时间:2024/05/21 23:34
A. Amr and Music
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.

Amr has n instruments, it takes ai days to learni-th instrument. Being busy, Amr dedicatedk days to learn how to play the maximum possible number of instruments.

Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.

Input

The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively.

The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.

Output

In the first line output one integer m representing the maximum number of instruments Amr can learn.

In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.

if there are multiple optimal solutions output any. It is not necessary to use all days for studying.

Sample test(s)
Input
4 104 3 1 2
Output
41 2 3 4
Input
5 64 3 1 1 2
Output
31 3 4
Input
1 34
Output
0
Note

In the first test Amr can learn all 4 instruments.

In the second test other possible solutions are: {2, 3, 5} or{3, 4, 5}.

In the third test Amr doesn't have enough time to learn the only presented instrument.


题意:

可以理解为:一个人有很多个知识点要学习,对于每个知识点,学习需要一定的时间,但是自己的时间有限。

问如何在有限的时间内,学习到尽可能多的知识点。(即要求学习知识点的个数最多)


分析:

很明显的贪心题目,对于知识点的学习,如果想要学习的个数最多,那么一定要从小的开始学习。



AC:

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <set>#include <map>#include <math.h>using namespace std;#define N 10010#define LL __int64struct LNode{int x,y;}f[N];int cmd(LNode x,LNode y){return x.x<y.x;}int ans[N];int len=0;int main() {//freopen("in.in","r",stdin);//freopen("out.out","w",stdout);int n,k;scanf("%d %d",&n,&k);for(int i=0;i<n;i++){scanf("%d",&f[i].x);f[i].y=i;}len =0;sort(f,f+n,cmd);int num=0;int t=0;while(k-f[t].x>=0){num++;k-=f[t].x;ans[len++]=f[t].y+1;t++;if(t==n) break;}printf("%d\n",num);for(int i=0;i<len;i++){if(i==0) printf("%d",ans[i]);else printf(" %d",ans[i]);}printf("\n");return 0;}




0 0