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 ...
随机推荐
- SQL数据分组后取最大值或者取前几个值(依照某一列排序)
今日做项目的时候,项目中遇到须要将数据分组后,分组中的最大值,想了想,不知道怎么做.于是网上查了查,最终找到了思路,经过比較这个查询时眼下用时最快的,事实上还有别的方法,可是我认为我们仅仅掌握最快的方 ...
- HDOJ How many ways?? 2157【矩阵高速幂】
How many ways? ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- SIFT算法中DoG特征点的修正
SIFT算法中,在DoG空间找到极值点后,需要对极值点进行修正,本文主要详细的讲解一下为什么需要修正,以及如何对极值点进行修正. 下图演示了二维函数离散空间得到的极值点与连续空间的极值点之间的差别 利 ...
- ShopMall
https://github.com/KingsleyYau/ShopMall-Android https://github.com/KingsleyYau/ShopMall-iOS https:// ...
- Django 之 form表单
Django中的Form表单 1.背景 平时我们在书写form表单时,经常都是手动的去写一些input标签,让用户输入一些功能,进行一些校验的判断,等等.Django中的form表单就能够帮我们去实现 ...
- (转)React Native 使用react-native-image-picker库实现图片上传功能
react-native-image-picker作为一个集成相机和相册的功能的第三方库,因为其使用相对简单受到前端开发人员的喜爱. react-native-image-picker使用 首先,安装 ...
- Uboot中start.S源码的指令级的详尽解析【转】
本文转载自:http://www.crifan.com/files/doc/docbook/uboot_starts_analysis/release/html/uboot_starts_analys ...
- Could not load file or assembly 'MyAssembly.XmlSerializers
https://stackoverflow.com/questions/17755559/could-not-load-file-or-assembly-myassembly-xmlserialize ...
- YTU 2419: C语言习题 等长字符串排序
2419: C语言习题 等长字符串排序 时间限制: 1 Sec 内存限制: 128 MB 提交: 650 解决: 249 题目描述 在主函数中输入n(n<=10)个等长的字符串.用另一函数对 ...
- css盒子模型详解一
什么是CSS的盒子模式呢?为什么叫它是盒子?先说说我们在网页设计中常听的属性名:内容(content).填充(padding).边框(border).边界(margin), CSS盒子模式都具备这些属 ...