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 ...
随机推荐
- easyui datagrid client搜索、分页、排序
easyui datagrid的排序默认是server端排序.能够用sorter实现client排序[2].client分页可用filter实现[3].client搜索相同能够用filter实现. 不 ...
- android-problem——remount of /system failed: Read-only file system
adb remount后仍旧不能对system进行读写.需要进行adb disable-verity 在Android6.0 (Android M)userdebug版本上(eng版本不存在该问题), ...
- PHP读取excel(4)
这一小节内容主要是PHPExcel读取少量excel数据,具体代码如下: <?php //数据较少的时候,一次性读取出来放到数组里 header("Content-Type:text/ ...
- HDU 1312 Red and Black 第一题搜索!
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码(转)
调用的API为: String[] upload_file( String group_name,//组名,不指定则可设为null long file_size,//文件大小,必须制定 UploadC ...
- Linux编程---进程通信
Linux的通信方式主要有分类有以下几种: -匿名管道和FIFO有名管道 -消息队列,信号量和共享存储 -套接字 对于套接字的进程通信,我就留在套接字的文章中再写了. 一.管道 管道是最古老的进程通信 ...
- iOS清理WebView的缓存
NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; ...
- STL review:vector & string & map & struct
I.vector 1.头文件:#include<vector> //容器vector是一个能实现随机存取.插入删除的动态数组,还可以当栈使. ...
- HDFS vs. MongoDB
HDFS MongoDB 共同点 http://www.mongoing.com/wp-content/uploads/2016/08/MDBSH2016/TJ_MongoDB+Spark.pdf 横 ...
- group by where having 联合使用
having子句与where有相似之处但也有区别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先执行.而where子句在查询过程中执行优 ...