沿时间轴枚举,发现关键时间点在于新题目被锁定的前一时间,那是新的题目还没有被锁定并且距离旧的题目已经被锁定的最晚时间,对这些时间点进行操作

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int flag,s;
};
node c[];
bool cmp(node x,node y){
if(x.s!=y.s)
return x.s<y.s;
return x.flag<y.flag;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int m;
cin>>m;
while(m--){
int n,t,a,b;
cin>>n>>t>>a>>b;
int suma=,sumb=;
for(int i=;i<=n;++i){
cin>>c[i].flag;
if(c[i].flag)
++sumb;
}
suma=n-sumb;
for(int i=;i<=n;++i)
cin>>c[i].s;
sort(c+,c++n,cmp);
int now=;
int tempa=,tempb=;
int ans=;
for(int i=;i<=n;++i){//枚举当前时间c[i].s-1,即为当前题目被锁定的时间以前
//当前时间及以前被锁定的题目都要完成,当前时间只完成前i-1道已锁定的题目以及空余时间可以做的题目
int numa=min(suma-tempa,(c[i].s--now)/a);//如果完成锁定题目以外还有空余时间,计算得到空余时间可以解决的最大简单题数量
int numb=min(sumb-tempb,(c[i].s--now-numa*a)/b);//如果解决完简单题还有空余时间,计算得到空余时间可以解决的最大复杂题数量
if(numa<)
numa=;
if(numb<)
numb=;
if(now<=c[i].s-)//now表示完成已经锁定的题目(前i-1道)需要的时间,如果当前时间可以完成这些已经锁定的题目,答案才会更新
ans=max(ans,numa+numb+i-);
if(c[i].flag){
now+=b;
++tempb;//已锁定的复杂题
}
else{
now+=a;
++tempa;//已锁定的简单题
}
if(now>t)//完成锁定的题目需要的时间超出上限,那么就做不了更多的题目了,break
break;
if(i==n)//如果全部题目都已经锁定并且完成时间不超出上限
ans=n;
}
cout<<ans<<"\n";
}
return ;
}

Codeforces Round #610 (Div. 2)C(贪心,思维)的更多相关文章

  1. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  2. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  3. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  4. Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索

    https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. Codeforces Round #303 (Div. 2) D 贪心

    D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  8. Codeforces Round #545 (Div. 2) D 贪心 + kmp

    https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中, ...

  9. Codeforces Round #547 (Div. 3) G 贪心

    https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...

随机推荐

  1. try_except_finally

    blog: python中的try/except/else/finally  python文档:错误和异常 与其他语言相同,在python中,try/except语句主要是用于处理程序正常执行过程中出 ...

  2. AcWing 1010. 拦截导弹

    //贪心加dp #include<iostream> using namespace std ; ; int n; int q[N]; int f[N]; int g[N];//存每个序列 ...

  3. 棋盘划分问题中4的k次方减一是三的倍数

    1.数学归纳法(万物皆可数学归纳) ①当n=1时:4-1=3(是三的倍数) ②假设n-1成立证明n成立:4n-1=4n-1*(4-1)+4n-1-1 =3*4n-1+(4n-1-1) 所以4n-1%3 ...

  4. python多线程返回值的实现与处理

    题目: # 编写一个python程序,创建两个子线程,分别到下面的网址获取文本内容# http://mirrors.163.com/centos/6/isos/x86_64/README.txt# h ...

  5. Weather

    Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such nat ...

  6. 转载:TDM协议

    转自http://www.wangdali.net/i2s/ 1. PCM简介 PCM (Pulse Code Modulation) 是通过等时间隔(即采样率时钟周期)采样将模拟信号数字化的方法.图 ...

  7. Centos7搭建Apache2.4

    我不多说废话了,相信在座的都应该明白怎么安装Apache2.4,我这才用yum源安装的,我个人认为这样安装的话,可以节省一些时间,有的网络不是很好,要等一段时间. 配置与Apache2.2的版本有点变 ...

  8. hdu2328 后缀树

    #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #in ...

  9. Spring AOP操作action时无法注入,报NullPointer异常

    Spring AOP操作action时无法注入,报NullPointer异常当使用Spring AOP对action层进行操作时,会出现注入失败的问题,出现空指针异常.原因是一般struts2+spr ...

  10. mybatis(六):设计模式 - 装饰器模式