目录

题目链接

AGC027 A - Candy Distribution Again

题解

贪心即可

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1; char c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 100007;
int a[maxn];
int main() {
int n = read(),k = read();
for(int i = 1;i <= n;++ i) a[i] = read();
std::sort(a + 1, a + n + 1);
int ans = 0;
for(int i = 1;i <= n;++ i) {
if(i < n) { if(a[i] <= k ) k -= a[i],ans ++;}
else if(i == n && a[i] == k) ans ++;
else break;
}
print(ans);
pc('\n');
}

AGC027 A - Candy Distribution Again的更多相关文章

  1. HDU 5291 Candy Distribution DP 差分 前缀和优化

    Candy Distribution 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5291 Description WY has n kind of ...

  2. HDU 5291 Candy Distribution

    Candy Distribution Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. Candy Distribution

    Kids like candies, so much that they start beating each other if the candies are not fairly distribu ...

  4. poj3372 Candy Distribution

    可以证明: f(k) = k *(k - 1)/ 2 (1 ≤ k ≤ n)是n的完全剩余系当且仅当n = 2 ^ t. http://poj.org/problem?id=3372

  5. [AtCoder AGC27A]Candy Distribution Again

    题目大意:把$x$个糖果分给$n$个人,必须分完,如果第$i$个人拿到$a_i$个糖果,就会开心,输出最多多少人开心 题解:从小到大排序,判断是否可以让他开心,注意最后判断是否要少一个人(没分完) 卡 ...

  6. [AGC027A]Candy Distribution Again

    Description AGC027A 你有一些糖果,你要把这些糖果一个不剩分给一些熊孩子,但是这帮熊孩子只要特定数目的糖果,否则就会不开心,求最多的开心人数. Solution 如果\(\sum a ...

  7. 【赛事总结】◇赛时·8◇ AGC-027

    [赛时·8]AGC-027 日常AGC坑……还好能涨Rating +传送门+ ◇ 简单总结 感觉像打多校赛一样,应该多关注一下排名……考试的时候为了避免影响心态,管都没有管排名,就在那里死坑B题.最后 ...

  8. Candy 解答

    Question There are N children standing in a line. Each child is assigned a rating value. You are giv ...

  9. 【Atcoder】AGC027 题解

    A - Candy Distribution Again 大意:有x个糖给n个小朋友,必须分完,小朋友得到糖数为一个确切值的时候小朋友会开心,求最多的开心数 题解 直接排序然后贪心分,如果分到最后一个 ...

随机推荐

  1. Reverse Words in a String I & Reverse Words in a String II

    Reverse Words in a String I Given an input string, reverse the string word by word. For example,Give ...

  2. Linux内存管理6---伙伴算法与slab

    1.前言 本文所述关于内存管理的系列文章主要是对陈莉君老师所讲述的内存管理知识讲座的整理. 本讲座主要分三个主题展开对内存管理进行讲解:内存管理的硬件基础.虚拟地址空间的管理.物理地址空间的管理. 本 ...

  3. DataTables 1.10.x与1.9.x参数名对照表

    Datatables 1.10.x在命名上与1.9.x的有区别,新版的使用的是驼峰的命名规则,而之前的是采用匈牙利命名规则 当然,这些变化都是向下兼容的,你可以继续使用旧版本的api方法的参数和名称. ...

  4. 『转载』hadoop2.x常用端口、定义方法及默认端口

    『转载』hadoop2.x常用端口.定义方法及默认端口 1.问题导读 DataNode的http服务的端口.ipc服务的端口分别是哪个? NameNode的http服务的端口.ipc服务的端口分别是哪 ...

  5. zabbix系列(十)zabbix添加对zookeeper集群的监控

    1.应用场景描述 在目前公司的业务中,有部分ESB架构用ZooKeeper作为协同服务的场景,做好ZooKeeper的监控很重要. 2.ZooKeeper监控要点 系统监控 内存使用量    ZooK ...

  6. centos6.5环境基于conga的web图形化界面方式配置rhcs集群

    一.简介 RHCS 即 RedHat Cluster Suite ,中文意思即红帽集群套件.红帽集群套件(RedHat Cluter Suite, RHCS)是一套综合的软件组件,可以通过在部署时采用 ...

  7. Mysql复习大全(转)

    基础知识: 1.数据库的连接 mysql -u -p -h -u 用户名 -p 密码 -h host主机 2.库级知识 显示数据库: show databases; 选择数据库: use dbname ...

  8. robotium之不标准select控件

    今天写脚本,遇到一个联合查询框 即:下拉框选择,输入框输入搜索条件,点击查询按钮 如图样式: 用uiautomatorviewer查看元素:无ID,无name,无desc 看到这我瞬间尴尬了,该咋办呢 ...

  9. bert 词典扩充方案

  10. 用javascript判断当前是安卓平台还是ios平台

    通常判断运行环境都是通过navigator.userAgent if (/android/gi.test(navigator.userAgent)){ // todo : android} if (/ ...