题解:CF913D Too Easy Problems
题意
给定一场考试,考试会持续
毫秒,由 道题目组成,你可以用 毫秒解决第 个问题,每个问题给定一个整数 。 要求你选出一个试题集合
,若该集合大小为 ,它应满足 ,你需要最大化 。
分析
显然所做的题数就应该是得分,因为不得分的题没有做的必要。
容易发现做的题越多,耗时也越多,同时能够提供分数的题越少,显然有单调性。
考虑二分答案。
我们在钦定了答案
时间复杂度
Code
#include<bits/stdc++.h> using namespace std; #define maxn 200005 struct test { int a, t, id; test(int A, int T, int I): a(A), t(T), id(I) {} }; vector<test> con, tmp, ans; bool chk(int k, int T) { tmp.clear(); for(auto [a, t, i]:con) if(a>=k) tmp.emplace_back(a, t, i); sort(tmp.begin(), tmp.end(), [](test &a, test &b){return a.t<b.t;}); int cnt=0; for(auto [a, t, i]:tmp) { if(T<t) break; cnt++, T-=t; } return cnt>=k; } int main() { int n, T; cin>>n>>T; for(int i=1, a, t;i<=n;i++) cin>>a>>t, con.emplace_back(a, t, i); int l=0, r=3e5; while(l+1<r) { int mid=(l+r)>>1; if(chk(mid, T)) l=mid, ans=tmp; else r=mid; } cout<<l<<'\n'<<l<<'\n'; for(int i=0;i<l;i++) cout<<ans[i].id<<' '; }
本文作者:Jimmy-LEEE
本文链接:https://www.cnblogs.com/redacted-area/p/18405332
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
题解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步