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 learn i-th instrument. Being busy, Amr dedicated k 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 nk (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 10
4 3 1 2
output
4
1 2 3 4
input
5 6
4 3 1 1 2
output
3
1 3 4
input
1 3
4
output
0

结构体排序,每次选最小。
 #include <bits/stdc++.h>
using namespace std; struct Node
{
int day;
int num;
}; int comp(const void * a,const void * b);
int main(void)
{
int n,k;
int sum;
Node s[];
int ans[];
int box; scanf("%d%d",&n,&k);
for(int i = ;i < n;i ++)
{
scanf("%d",&s[i].day);
s[i].num = i + ;
}
qsort(s,n,sizeof(Node),comp); sum = box = ;
for(int i = ;i < n;i ++,box ++)
{
sum += s[i].day;
if(sum > k)
break;
ans[box] = s[i].num;
}
printf("%d\n",box);
for(int i = ;i < box;i ++)
{
printf("%d",ans[i]);
if(i + < box)
printf(" ");
}
if(box)puts(""); return ;
} int comp(const void * a,const void * b)
{
return (*(Node *)a).day - (*(Node *)b).day;
}

CF Amr and Music (贪心)的更多相关文章

  1. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  2. CF Soldier and Badges (贪心)

    Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. CF Amr and Pins (数学)

    Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. CF Anya and Ghosts (贪心)

    Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. cf 853 A planning [贪心]

    题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...

  6. CF 1082E Increasing Frequency(贪心)

    传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...

  7. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...

  8. CF 161B Discounts(贪心)

    题目链接: 传送门 Discounts time limit per test:3 second     memory limit per test:256 megabytes Description ...

  9. CF 268E Playlist(贪心)

    题目链接: 传送门 Playlist time limit per test:1 second     memory limit per test:256 megabytes Description ...

随机推荐

  1. UVALive 7278 Game of Cards (sg函数)

    Game of Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/G Description Alice and Bob ...

  2. Spring Autowiring by Type

    In Spring, "Autowiring by Type" means, if data type of a bean is compatible with the data ...

  3. Arduino Due, Maple and Teensy3.0 的 W5200性能测试

    开源平台中以太网连接方案里W5100是众所周知的,W5200正在此领域越来越受欢迎.这个测试结果是在Arduino Due(Atmel CortexM3-84Mhz), Maple(ST Cortex ...

  4. ASP.NET MVC- 数据验证机制

    ASP.NET MVC的数据验证机制,比起ASP.NET WEBFORM那种高效很多.下面记录以下两个示例,以便日后方便查阅. 方式一:在Controller里通过AddModelError方法返回错 ...

  5. java实现抓取某公司官网新闻

    这里先说一下,实习期的一个项目,当时并没有该合作公司的获取新闻的接口,但是项目又急着上线,所以总监就让我来做一个简单的抓取,现将主要的工具类NewsUtil.java贴出来供大家参考. NewsUti ...

  6. 用Emacs 写python了

    之前都是用python 自带的IDLE 写 python 的,现在换了Emacs,感觉真是不错,爽. 截图留念: 用了sr-speedbar ,顿时有了IDE 的感觉,是不是很爽. 版权声明:本文为博 ...

  7. Python 结巴分词模块

    原文链接:http://www.gowhich.com/blog/147?utm_source=tuicool&utm_medium=referral PS:结巴分词支持Python3 源码下 ...

  8. Python3爬虫学习

    学了几天python3,发现目前学到的与爬虫还是关系不大,所以现在准备爬虫和语言同步学习. 2016.8.9晚 先从最简单的开始,爬取指定url的所有内容: #encoding:UTF-8 impor ...

  9. UdpClient的Connect究竟做了什么(转)

    最近在写一个音频通信的系统,因为需要还要处理其他事件,所以就自己设计底层的通信协议,用了不少底层的Socket编程(.Net Framework),搞清楚了不少细节问题. 先做一些铺垫工作.音频系统服 ...

  10. 学习JSONP

    最近自己研究 跨域调用js,然后 发现 有jsonp 这种技术,在Jquery中可以使用,于是 研究下原理 发现: 其实 就是 利用<script>的跨域访问的能力. 调用 服务端 返回的 ...