给出考试时间和考试需要准备的时间,问最早考完所有科目的时间

二分答案 NlogN

二分抄神犇的写法 感觉挺舒服的嘻嘻嘻

 #include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+;
int N,M,d[MAXN],w[MAXN],cnt[MAXN];
void read(int &x){
x=;
register char c=getchar();
while(c<||c>)
c=getchar();
for(;c>=&&c<=;c=getchar())
x=(x<<)+(x<<)+c-;
}
bool check(int x)
{
memset(cnt,,sizeof(cnt));
int ans = ,val = ;
for (int i=x; i>=; i--)
if (d[i]&&++cnt[d[i]]==&&w[d[i]]<i-M+ans+)
{
ans++;
val+=w[d[i]];
}
return ans == M && val+M<=x;
}
int main()
{
read(N),read(M);
for (int i=; i<=N; i++)
read(d[i]);
for (int i=; i<=M; i++)
read(w[i]);
int first = ;
int last = N;
int mid;
int best = -;
while (first <= last)
{
mid = (first + last)/;
if (check(mid))
{
last = mid-;
best = mid;
}
else
{
first = mid+;
}
}
printf("%d\n",best);
return ;
}

codeforces 732/D 二分的更多相关文章

  1. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

  2. codeforces 732D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...

  3. CodeForces 359D (数论+二分+ST算法)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...

  4. CodeForces 163B Lemmings 二分

    Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...

  5. CodeForces - 589A(二分+贪心)

    题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  7. CodeForces - 1059D(二分+误差)

    链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...

  8. Letters CodeForces - 978C (二分)

    Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...

  9. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

随机推荐

  1. Visual Studio 启动修复命令

    今天VS启动不了了,连命令行的 devenv.exe /? 都执行不了,看不到帮助命令了,记性不好,以前看过但没记住呀,还好我装了两个不同版本的VS, 另一个VS的帮助命令还是可以看到的.虽然修复了, ...

  2. numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

    python35用pip安装scipy的时候报错 numpy.distutils.system_info.NotFoundError: no lapack/blas resources found 原 ...

  3. IntelliJ Idea 常用快捷键 列表(实战终极总结!!!!)

    IntelliJ Idea 常用快捷键 列表(实战终极总结!!!!) 1. -----------自动代码-------- 常用的有fori/sout/psvm+Tab即可生成循环.System.ou ...

  4. 【python】类中@property使用

    在绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单,但是,没办法检查参数,导致可以把成绩随便改: s = Student() s.score = 9999 这显然不合逻辑.为了限制score的 ...

  5. Silverlight管理系统源码(用于开发ERP、OA、CRM、HR、进销存、财务等系统之用)

    Silverlight大型管理系统源代码(支持创建ERP.OA.CRM.HR.进销存.财务等系统之用) 可用于开发以下系统 SilverlightERP SilverlightCRM Silverli ...

  6. 将表里的数据批量生成INSERT语句的存储过程

    有时候,我们需要将某个表里的数据全部导出来,迁移到另一个相同结构的库中,这里可以采取一个简便的方法,通过一个存储过程批量导出数据并生成SQL语句,非常方便.存储过程如下: )) as begin de ...

  7. (转)JPEG图片数据结构分析- 附Png数据格式详解.doc

       一.简述 JPEG是一个压缩标准,又可分为标准JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级别的压缩,不过,这种压 ...

  8. spring component-scan filter

    (参考的Spring version : 4.1.6.RELEASE) 我们通常会使用component-scan来进行bean的加载,但是它里面的实现机制却是一知半解.根据原码来理解一下,可能会更加 ...

  9. eclipse默认文件编码

    eclipse里 就是在eclipse.ini文件里添加一行-Dfile.encoding=utf-8即可 -startup plugins/org.eclipse.equinox.launcher_ ...

  10. C# 时间类型

    字符型转换为字符串// C 货币 2.5.ToString("C"); // ¥2.50 // D 10进制数 25.ToString("D5"); // 25 ...