题目分析

没有题目分析……

寄存一下神奇反悔贪心

  1. #include<bits/stdc++.h>
  2. const int maxn = ;
  3.  
  4. struct node
  5. {
  6. int a,b;
  7. node(int x=, int y=):a(x),b(y) {}
  8. bool operator < (node x) const
  9. {
  10. return a < x.a;
  11. }
  12. }a[maxn],b[maxn];
  13. int T,n,m,mn,tot;
  14. int mx,ans,cnt1,cnt2;
  15.  
  16. int read()
  17. {
  18. char ch = getchar();
  19. int num = ;
  20. bool fl = ;
  21. for (; !isdigit(ch); ch=getchar())
  22. if (ch=='-') fl = ;
  23. for (; isdigit(ch); ch=getchar())
  24. num = (num<<)+(num<<)+ch-;
  25. if (fl) num = -num;
  26. return num;
  27. }
  28. int main()
  29. {
  30. freopen("assassin.in","r",stdin);
  31. freopen("assassin.out","w",stdout);
  32. T = read();
  33. while (T--)
  34. {
  35. n = read(), m = read();
  36. cnt1 = cnt2 = mx = ans = tot = , mn = m+;
  37. for (int i=; i<=n; i++)
  38. {
  39. int x = read(), y = read();
  40. if (y) a[++cnt1] = node(x, y), mn = std::min(mn, x), tot += y;
  41. else b[++cnt2] = node(x, y);
  42. }
  43. std::sort(a+, a+cnt1+);
  44. std::sort(b+, b+cnt2+);
  45. if (m >= mn){
  46. mx = tot+, ans = mn;
  47. if (mx >= n){
  48. printf("%d %d\n",n,mn);
  49. continue;
  50. }
  51. cnt2 -= mx-cnt1;
  52. for (int i=; i<=cnt1; i++) b[++cnt2] = a[i];
  53. std::sort(b+, b+cnt2+);
  54. for (int i=; i<=cnt2&&mx<n; i++)
  55. if (ans+b[i].a <= m) mx++, ans += b[i].a;
  56. else break;
  57. printf("%d %d\n",mx,ans);
  58. }else{
  59. mx = ;
  60. for (int i=; i<=cnt2; i++)
  61. if (b[i].a <= m) m -= b[i].a, mx++, ans += b[i].a;
  62. printf("%d %d\n",mx,ans);
  63. }
  64. }
  65. return ;
  66. }

END

【贪心】10.24assassin的更多相关文章

  1. UVALive 8519 Arrangement for Contests 2017西安区域赛H 贪心+线段树优化

    题意 等价于给一个数列,每次对一个长度为$K$的连续区间减一 为最多操作多少次 题解: 看样例猜的贪心,10分钟敲了个线段树就交了... 从1开始,找$[i,i+K]$区间的最小值,然后区间减去最小值 ...

  2. WC2016自测

    挑战NPC 原题链接 爆搜20分,贪心10分,网络流30分 //挑战NPC #include <cstdio> #include <cstring> #include < ...

  3. [蓝桥杯]2016蓝桥省赛B组题目及详解

    /*——————————————————————————————————————————————————————————— [结果填空题]T1 (分值:3) 题目:煤球数目 有一堆煤球,堆成三角棱锥形 ...

  4. 2017 清北济南考前刷题Day 6 morning

    T1 贪心 10 元先找5元 20元 先找10+5,再找3张5 #include<cstdio> using namespace std; int m5,m10,m20; int main ...

  5. NOIP模拟测试17「入阵曲&#183;将军令&#183;星空」

    入阵曲 题解 应用了一种美妙移项思想, 我们先考虑在一维上的做法 维护前缀和$(sum[r]-sum[l-1])\%k==0$可以转化为 $sum[r]\% k==sum[l-1]\%k$开个桶维护一 ...

  6. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  7. 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...

  8. 2018.10.27 codeforces402D. Upgrading Array(数论+贪心)

    传送门 唉我觉得这题数据范围1e5都能做啊... 居然只出了2000 考完听zxyzxyzxy说我的贪心可以卡但过了? 可能今天本来是0+10+00+10+00+10+0只是运气好T1T1T1骗了10 ...

  9. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

随机推荐

  1. Jeasyui的datagrid前端分页要点

    Jeasyui的分页有两种方式: 1. 服务器端分页,是真正的分页,datagridview的pager会自动把pageSize和pageNum传到后台,后台根据根据pageSize和pageNum构 ...

  2. 源码分析(一) 进程cleos的命令解析

    EOS版本:4.0   一.进程cleos的作用   cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^   准确地说 ...

  3. Centos 6.x 安装 Redis

    本文以Centos6.8为例子,来进行演示. 1:下载最新版的Redis,比如我们安装在根目录下的redis文件下中 tar zxvf http://download.redis.io/release ...

  4. ES6新特性使用小结(二)

    六.Array 扩展 /* * Array Api Array.of 数组的构建 * */ { let arr = Array.of(, , , , , ); console.log(arr); // ...

  5. Ubuntu 下修改Tomcat和Jetty默认的JDK和初始内存

    修改/etc/default/tomcat  或者  /etc/default/jetty   文件 中的 JAVA_HOME 和 JAVA_OPTS

  6. 传纸条(scrip)

    传纸条(scrip) 题目背景 Awson是某国际学校信竞组的一只菜鸡.每次竞赛考试都只能垫底.终于有一天,他决定不再苟活,发挥他的人脉优势,准备在一次竞赛考试时传纸条作弊. 题目描述 他预先知道了考 ...

  7. Redis set(集合)

    Redis 的 Set 是 String 类型的无序集合,元素不允许重复. Redis 中集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是 O(1). 集合中最大的元素数为 232 - 1 ( ...

  8. Dubbo封装rest服务返回结果

    由于Dubbo服务考虑到一个是给其他系统通过RPC调用,另外一个是提供HTTP协议本身系统的后台管理页面,因此Dubbo返回参数在rest返回的时候配置拦截器进行处理. 在拦截器中,对返回参数封装成如 ...

  9. <Android 应用 之路> 聚合数据SDK

    聚合数据介绍 聚合数据是一个为智能手机开发者,网站站长,移动设备开发人员及图商提供原始数据API服务的综合性云数据平台.包含手机聚合,网站聚合,LBS聚合三部分,其功能类似于Google APIS.[ ...

  10. LNK2005错误——重复定义错误

    编程中经常能遇到LNK2005错误——重复定义错误,其实LNK2005错误并不是一个很难解决的错误.弄清楚它形成的原因,就可以轻松解决它了. 造成LNK2005错误主要有以下几种情况: 1.重复定义全 ...