Codeforces732D Exams
显然要二分答案,然后对于一个天数,我们来判断是否可以通过所有考试,这里就贪心来安排就好了。
首先我们希望每门课的考试时间越晚越好,然后就是先复习最早开始的考试。
#include <bits/stdc++.h>
using namespace std; vector<int> pos[];
int d[];
int a[];
int n, m; bool judge(int mid)
{
vector<pair<int, int>> course;
for (int i = ; i <= m; i++)
{
vector<int>::iterator it = upper_bound(pos[i].begin(), pos[i].end(), mid);
if (it == pos[i].begin())
return false;
it--;
course.push_back({*it, i});
}
sort(course.begin(), course.end());
int used = ;
for (auto &c : course)
{
if (c.first - - used < a[c.second])
return false;
used += a[c.second] + ;
}
return true;
} int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
scanf("%d", d + i);
if (d[i] > )
pos[d[i]].push_back(i);
}
for (int i = ; i <= m; i++)
scanf("%d", a + i);
int l = , r = n;
if (!judge(n))
puts("-1");
else
{
while (l < r)
{
int mid = l + r >> ;
if (judge(mid))
r = mid;
else
l = mid + ;
}
printf("%d", l);
}
return ;
}
Codeforces732D Exams的更多相关文章
- 二分算法题目训练(二)——Exams详解
CodeForces732D——Exams 详解 Exam 题目描述(google翻译) Vasiliy的考试期限将持续n天.他必须通过m门科目的考试.受试者编号为1至m. 大约每天我们都知道当天可以 ...
- CF732D. Exams[二分答案 贪心]
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #377 (Div. 2) D. Exams(二分答案)
D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...
- codeforces 480A A. Exams(贪心)
题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #377 (Div. 2) D. Exams 二分
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- cf492C Vanya and Exams
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf479C Exams
C. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- POJ训练计划1035_Spell checker(串处理/暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18418 Accepted: 6759 De ...
- mysql关闭skip-grant-tables快速重置mysql密码
如果你忘记了mysql密码几乎是没有什么好办法可以直接修改密码了,但我们可以在my.ini把加上skip-grant-tables,然后重启mysql就不需要密码了,这时我们再修改root密码,最后再 ...
- ADO直接调用ACESS数据库MDB
1.ADO用ODBC链接不会出现堆栈溢出. 2.直接用ADO链接,因为对象不是NEW出来的,导致其成员变量也是栈上的,数组申请过大,栈溢出. 用VECTOR或者NEW对象,应该能解决.
- 苹果应用内支付(iOS IAP)的流程与常用攻击方式
1. 客户端直接verify苹果的receipt 如果verify成功 自行发放商品 2. 客户端将receipt传给server,由server进行验证并发放商品 按照安全性原则, 客户端的所有信息 ...
- MD5加密实现类不是Windows平台下联邦信息处理标准验证过的加密算法的一部分
在.NET应用程序中,MD5CryptoServiceProvider实例化时,造成This implementation is not part of the Windows Platform FI ...
- 推断php操作mysql(添删改查)是否成功
近期在使用CI框架 , 可是里面的数据库操作没有ThinkPhp方便 , 不知道数据库操作的反馈信息 , 仅仅好借助原生方法来推断是否操作数据库成功 推断php操作mysql(添删改查)是否成功,主要 ...
- MFC中CAsyncSocket和CSocket
原文链接:https://blog.csdn.net/libaineu2004/article/details/40395917 摘要部分重点: 1.CAsyncSocket类逐个封装了WinSock ...
- Java IO、BIO、NIO、BIO
一.什么是IO/NIO: IO:即BIO(Blocking IO):面向流的.同步阻塞式IO:(JDK1.4之前唯一的选择) NIO:面向缓冲的.同步非阻塞式IO:三大核心部分:Selector.Ch ...
- linux 设备驱动程序中的一些关联性思考
首先,个人感觉设备驱动程序与应用程序中的文件操作隔得有点远,用户空间不论是直接使用系统调用还是库函数都是通过系统调用的接口进入内核空间代码的.但是看过一个博客的分析整个过程,感觉中间层太过麻烦,必须经 ...
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...