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

二分答案 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. CAD的API们

    AutoCAD有4种API,.net,lisp,activex和ObjectARX(C++).它们都是用来给cad写插件什么的,依赖cad运行. 另有一个RealDWG SDK,这是用来读写dwg或d ...

  2. Linux下安装php加速器xcache

    一.环境说明 php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini Nginx安装目录:/usr/local/nginx Ng ...

  3. Tcpdump命令详解

    简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...

  4. PowerDesigner里数据表里AUTO_INCREMENT(自增)的设置

    使用流程: File->New Model->Model types->Physical Data Model->Physical Diagram 在下边DBMS里选择:MyS ...

  5. ant 自定义taskdef的工作目录

    上次同事在用ant执行多层目录的测试用例的时候遇到了一些问题,也就是自定义的taskdef的工作目录总是在开始执行ant的那个目录,而有一些地方用到了当前目录,因此很多测试用命的代码出现了“找不到自定 ...

  6. 用Visual Studio调试Windows和驱动程序

    由于本人能力有限,翻译不足之处敬请谅解,欢迎批评指正:sunylat@163.com Visual Studio版本:Visual Studio 2015企业版,中文环境. MSDN原文:https: ...

  7. 【摘】使用tail、head命令过滤行

    tail  -n  10  test.log   查询日志尾部最后10行的日志; tail -n +10 test.log    查询10行之后的所有日志; head -n 10  test.log  ...

  8. XMPP协议错误码

    302 重定向 尽管HTTP规定中包含八种不同代码来表示重定向,Jabber只用了其中一个(用来代替所有的重定向错误).不过Jabber代码302是为以后的功能预留的,目前还没有用到 400 坏请求  ...

  9. linker command failed with exit code 1 (use -vto see invocation)

    报这样的错误可能是同一个.m文件同时存在,要先把你新添加的.m文件彻底删除 Move to Trash 点击这个删除.然后clear一下,再在重新添加你所需要的文件即可解决.这次添加不要推进来,需要在 ...

  10. 配置VS使用winteracter

    一.winteracter是什么?为什么要用VS代替wide?winteracter 是一款强大的 Fortran 图形界面函数库,可方便的用 Fortran 生成GUI界面,对话框,菜单,绘图等操作 ...