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

二分答案 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. Sharepoint CAML 增删改查 List

    Lists.UpdateListItems 方法 (websvcLists) Windows SharePoint Services 3   Adds, deletes, or updates the ...

  2. mysql特殊处理

    mysql> create table ef (bc time);Query OK, 0 rows affected (0.03 sec) mysql> insert into ef va ...

  3. 三线程连续打印ABC

    package test5; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Reentr ...

  4. [系统集成] OpenLDAP使用AD密码

    关于OpenLDAP和AD帐号的整合,网上有大量的文档,绝大多数都不符合我们的需求,下面的方案是我经过调研.测试.修改.最终采用的. . 需求概述 公司网络中有两种帐号:OpenLDAP帐号和AD帐号 ...

  5. ruby中rsa加签解签方法

    # coding:utf-8require 'openssl'require 'base64'# rsa签名,文本内容和私钥路径def rsa_sign(data,private_key_path) ...

  6. DOMContentLoaded和jquery的ready和window.onload的顺序

    document.addEventListener('DOMContentLoaded', function(){ alert(1) }); window.onload=function(){ ale ...

  7. PRD

  8. OpenExplorer打开文件夹

    Eclipse中文件打开功能,可以到https://github.com/samsonw/OpenExplorer/downloads下载最新版本,将jar包放到eclipse的plugins目录中, ...

  9. 刷了OpenWrt Attitude Adjustment 12.09,很满意

    OpenWrt的这个新版本编译好的固件里集成了luci,图形界面还是很方便的. 装了wpad.qos之后,空间刚好剩下一点点,囧,4M闪存还是不够折腾啊. 发现一个bug:如果空间不够的情况下继续安装 ...

  10. Spark On Yarn中spark.yarn.jar属性的使用

    今天在测试spark-sql运行在yarn上的过程中,无意间从日志中发现了一个问题: spark-sql --master yarn // :: INFO Client: Requesting a n ...