题目分析

没有题目分析……

寄存一下神奇反悔贪心

 #include<bits/stdc++.h>
const int maxn = ; struct node
{
int a,b;
node(int x=, int y=):a(x),b(y) {}
bool operator < (node x) const
{
return a < x.a;
}
}a[maxn],b[maxn];
int T,n,m,mn,tot;
int mx,ans,cnt1,cnt2; int read()
{
char ch = getchar();
int num = ;
bool fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
int main()
{
freopen("assassin.in","r",stdin);
freopen("assassin.out","w",stdout);
T = read();
while (T--)
{
n = read(), m = read();
cnt1 = cnt2 = mx = ans = tot = , mn = m+;
for (int i=; i<=n; i++)
{
int x = read(), y = read();
if (y) a[++cnt1] = node(x, y), mn = std::min(mn, x), tot += y;
else b[++cnt2] = node(x, y);
}
std::sort(a+, a+cnt1+);
std::sort(b+, b+cnt2+);
if (m >= mn){
mx = tot+, ans = mn;
if (mx >= n){
printf("%d %d\n",n,mn);
continue;
}
cnt2 -= mx-cnt1;
for (int i=; i<=cnt1; i++) b[++cnt2] = a[i];
std::sort(b+, b+cnt2+);
for (int i=; i<=cnt2&&mx<n; i++)
if (ans+b[i].a <= m) mx++, ans += b[i].a;
else break;
printf("%d %d\n",mx,ans);
}else{
mx = ;
for (int i=; i<=cnt2; i++)
if (b[i].a <= m) m -= b[i].a, mx++, ans += b[i].a;
printf("%d %d\n",mx,ans);
}
}
return ;
}

END

最新文章

  1. hexo+next博客添加搜索
  2. 三、jQuery--jQuery基础--jQuery基础课程--第12章 jQuery在线聊天室
  3. #pragma data_seg 共享数据区(转)
  4. imx6 KEY_ROW4 power output high fail
  5. Report_客制化Excel报表中的XLS标记(案例)
  6. 【BZOJ】【3530】【SDOI2014】数数
  7. 胖client和瘦client
  8. hdu1031
  9. HackerRank The Chosen One [预处理][gcd]
  10. nginx启动脚本,手动编辑
  11. Visual Studio Code 调整字体大小
  12. 浏览器兼容的JS写法总结
  13. 【环套树+树形dp】Bzoj1040 [ZJOI2008] 骑士
  14. dotnet core高吞吐Http api服务组件FastHttpApi
  15. javascript 的线程问题
  16. 在windows上搭建SSH服务踩过的坑
  17. 第一次使用Android Studio时你应该知道的一切配置(一)
  18. php传值,传地址,传引用的区别
  19. JAVA常见算法题(三十二)---找规律
  20. 类的专有方法(__repr__)

热门文章

  1. IDEA打开项目格式问题
  2. Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
  3. csdn自动展开+去广告+净化剪切板+免登陆(如有侵权,立即删博)
  4. bzoj1095: [ZJOI2007]Hide 捉迷藏 动态点分治学习
  5. JsonModel&amp;AFNetWorking
  6. String类、StringBuilder类、StringBuffer类
  7. JVM类加载机制二
  8. Spring 整合 Quartz 实现动态定时任务(附demo)
  9. http://circles.arenaofthemes.com/
  10. HBuilder 做移动端app流程