目录

题目链接

AGC027 A - Candy Distribution Again

题解

贪心即可

代码

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #define gc getchar()
  5. #define pc putchar
  6. inline int read() {
  7. int x = 0,f = 1;
  8. char c = gc;
  9. while(c < '0' || c > '9') {if(c == '-')f = -1; char c = getchar();}
  10. while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
  11. return x * f;
  12. }
  13. void print(int x) {
  14. if(x < 0) {
  15. pc('-');
  16. x = -x;
  17. }
  18. if(x >= 10) print(x / 10);
  19. pc(x % 10 + '0');
  20. }
  21. const int maxn = 100007;
  22. int a[maxn];
  23. int main() {
  24. int n = read(),k = read();
  25. for(int i = 1;i <= n;++ i) a[i] = read();
  26. std::sort(a + 1, a + n + 1);
  27. int ans = 0;
  28. for(int i = 1;i <= n;++ i) {
  29. if(i < n) { if(a[i] <= k ) k -= a[i],ans ++;}
  30. else if(i == n && a[i] == k) ans ++;
  31. else break;
  32. }
  33. print(ans);
  34. pc('\n');
  35. }

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. mysql基本命令[转]

    1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...

  2. 【Python】批量查询-提取站长之家IP批量查询的结果v1.0

    0 前言 写报告的时候为了细致性,要把IP地址对应的地区给整理出来.500多条IP地址找出对应地区复制粘贴到报告里整了一个上午. 为了下次更好的完成这项重复性很高的工作,所以写了这个小的脚本. 1 使 ...

  3. docker在centos7系统镜像下遇到的一些问题

    一.成功安装服务后发现无法启动 报错为:Failed to get D-Bus connection: Operation not permitted 系统为centos7官方版镜像,源和依赖之类的都 ...

  4. CAP理论介绍

    经典CAP图 分布式系统的CAP理论:理论首先把分布式系统中的三个特性进行了如下归纳: ●一致性(C):在分布式系统中的所有数据备份,在同一时刻是否同样的值.(等同于所有节点访问同一份最新的数据副本) ...

  5. spring和hibernate集成事物管理配置方法

    spring+hibernate,采用声明式事务 1.声明式事务配置 * 配置SessionFactory * 配置事务管理器 * 事务的传播特性 * 那些类那些方法使用事务 2.编写业务逻辑方法 * ...

  6. Oracle查询表主键、外键

    项目中用到的一些Sql(oracle下的)总结: 1.查找表的所有索引(包括索引名,类型,构成列) select t.*,i.index_type from user_ind_columns t,us ...

  7. CSS的vertical-align

    转载自https://blog.csdn.net/FE_dev/article/details/75948659 说明 vertical-align属性,是CSS属性中一个比较重要的属性,也是比较不好 ...

  8. webpack中的output.filename 和output.chunkFilename

    filename应该比较好理解,就是对应于entry里面生成出来的文件名.比如: { entry: { "index": "pages/index.jsx" } ...

  9. 性能测试七:jmeter进阶之文件上传下载、定时器

    一.上传下载 上传: 1,POST请求,勾选 use …for post 2,同请求一起发送文件里,填写文件名称,参数名称 3,MIME类型: application/octet-stream(非必须 ...

  10. appium自动化测试之元素定位

    方法一 使用SDK中附带的uiautomatorviewer来定位 在SDK安装目录下的tools下有个uiautomatorviewer.bat批处理文件点击运行 运行后(注意appium desk ...