【贪心】10.24assassin
2024-08-28 11:41:06
题目分析
没有题目分析……
寄存一下神奇反悔贪心
#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
最新文章
- hexo+next博客添加搜索
- 三、jQuery--jQuery基础--jQuery基础课程--第12章 jQuery在线聊天室
- #pragma data_seg 共享数据区(转)
- imx6 KEY_ROW4 power output high fail
- Report_客制化Excel报表中的XLS标记(案例)
- 【BZOJ】【3530】【SDOI2014】数数
- 胖client和瘦client
- hdu1031
- HackerRank The Chosen One [预处理][gcd]
- nginx启动脚本,手动编辑
- Visual Studio Code 调整字体大小
- 浏览器兼容的JS写法总结
- 【环套树+树形dp】Bzoj1040 [ZJOI2008] 骑士
- dotnet core高吞吐Http api服务组件FastHttpApi
- javascript 的线程问题
- 在windows上搭建SSH服务踩过的坑
- 第一次使用Android Studio时你应该知道的一切配置(一)
- php传值,传地址,传引用的区别
- JAVA常见算法题(三十二)---找规律
- 类的专有方法(__repr__)
热门文章
- IDEA打开项目格式问题
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
- csdn自动展开+去广告+净化剪切板+免登陆(如有侵权,立即删博)
- bzoj1095: [ZJOI2007]Hide 捉迷藏 动态点分治学习
- JsonModel&;AFNetWorking
- String类、StringBuilder类、StringBuffer类
- JVM类加载机制二
- Spring 整合 Quartz 实现动态定时任务(附demo)
- http://circles.arenaofthemes.com/
- HBuilder 做移动端app流程