codeforces 732/D 二分
给出考试时间和考试需要准备的时间,问最早考完所有科目的时间
二分答案 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 二分的更多相关文章
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- codeforces 732D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- CodeForces 163B Lemmings 二分
Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...
- CodeForces - 589A(二分+贪心)
题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...
- 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 ...
- CodeForces - 1059D(二分+误差)
链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...
- Letters CodeForces - 978C (二分)
Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- Android学习六:Socket 使用
1socket的作用 通过http去获取服务器的数据在有些情况下是行不通的,所有使用socket与服务器通信也是必须掌握的 2.代码 好了上代码,代码中有解释,首先是简单的服务端代码 package ...
- 如何书写高质量的jQuery代码(转)
想必大家对于jQuery这个最流行的javascript类库都不陌 生,而且只要是前端开发人员肯定或多或少的使用或者接触过,在今天的这篇文章中,参考了一些资料及实际使用效率,将介绍一些书写高质量jQu ...
- 分布式id 实现方式
1. uuid 2. twitter的Snowflake 3. MongoDB ObjectID 4. Ticket Server 5. Instagram采用的方式(UUID方式)
- Docker之Web-UI
DockerUI 不支持多主机Command: docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock dock ...
- 【xargs使用】查询包含某字符串的所有文件
在initrd目录下,查找包含"Loading virtio.ko"的所有文件 cd initrd find . | xargs grep "Loading virtio ...
- MyBatis学习总结(七)——Mybatis缓存
一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...
- oracle远程连接太慢
场景:Oracle11G DB服务器上用sqlplus直接连很快(秒连),但加上服务名后却半天没反应.一台正式.一台测试都出现此问题. sqlplus:xnwz/xnwz 很快 sqlplus:xnw ...
- java反射学习笔记
1.java反射概念 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功 ...
- oracle两列相同的去重
源地址:https://zhidao.baidu.com/question/66722841.html 1.不含大字段(clob等)的表格: 1 2 3 4 5 6 7 8 9 --例子表格:crea ...
- CRM Xrm.Page 的对象层次结构