http://codeforces.com/contest/732/problem/D

这题我发现很多人用二分答案,但是是不用的。

我们统计一个数值all表示要准备考试的所有日子和。+m(这些时间用来考试)

那么这个all值就是理想的最小值。然后去前all个数找,贪心地复习最小的科目,然后有的考试的话,就优先考试。

如果经过这all天,复习完了(这个是肯定得),但是只是因为时间分配不好,导致没得考试(数据导致没得考试)

那么就暴力枚举后面的[all + 1, n]。有得考试就去考试,刚好考完就直接输出i就可以了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e5 + ;
int a[maxn];
int day[maxn];
void work() {
int n, m;
cin >> n >> m;
for (int i = ; i <= n; ++i) {
cin >> a[i];
}
LL all = m;
for (int i = ; i <= m; ++i) {
cin >> day[i];
all += day[i];
}
sort(day + , day + + m);
int lenday = ;
int now = ;
if (n < all) {
cout << "-1" << endl;
return;
}
for (int i = ; i <= all; ++i) {
if (a[i] == ) {
day[lenday]--;
if (day[lenday] == ) {
now++;
lenday++;
}
} else {
if (now) now--;
else {
day[lenday]--;
if (day[lenday] == ) {
now++;
lenday++;
}
}
}
}
if (now == ) {
cout << all << endl;
return;
}
for (int i = all + ; i <= n; ++i) {
if (a[i] == ) {
continue;
} else {
now--;
if (now == ) {
cout << i << endl;
return;
}
} }
cout << "-1" << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟的更多相关文章

  1. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #274 (Div. 2) C. Exams (贪心)

    题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...

  6. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  7. Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分

    A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)

     传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...

  9. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

随机推荐

  1. 机器学习:simple linear iterative clustering (SLIC) 算法

    图像分割是图像处理,计算机视觉领域里非常基础,非常重要的一个应用.今天介绍一种高效的分割算法,即 simple linear iterative clustering (SLIC) 算法,顾名思义,这 ...

  2. 京东ie6中轮播模块小图出现在大图上

    请大家给个评论,给个支持!呵呵 本人最新一套模版小清新童装母婴日韩风全屏轮播(上线风暴),在审核时审核失败,报的是“ie6中全屏海报轮播是小图出现在大图中间的兼容性错误” 而本人本机出现的是小图基本上 ...

  3. vs2012解决scanf,printf编译出错的问题

    转自http://www.th7.cn/Program/c/201303/127343.shtml 在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: er ...

  4. bzoj1072Perm——状压DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1072 数字串最多只有10位,所以考虑用状压: 压缩的状态是哪些数字被用过,这样可以从一种状态 ...

  5. 【转】值得推荐的C/C++框架和库

    偶然间在博客园前辈那里看到的,转载备用,日后研究. 原文链接:http://www.cnblogs.com/findumars/p/6891515.html Webbench是一个在linux下使用的 ...

  6. web.xml中<security-constraint>安全认证标签说明

      1.security-constraint元素 部署描述符中的<security-constraint>元素允许不通过编程就可以限制对某个资源的访问. <security-con ...

  7. Component概念

    转自:http://www.cnblogs.com/NEOCSL/archive/2012/05/06/2485227.html 1.总结 Component就是组建的意思,可以在DefaultPro ...

  8. Getting Started with OpenMP

    Getting Started with OpenMP* Abstract As you probably know by now, to get the maximum performance be ...

  9. Java创建线程的三种方法比较

    一般有三种方法,Thread,Runnable,Callable. Runnable和Callable的区别 (1)Callable规定的方法是call(),Runnable规定的方法是run(). ...

  10. 反射设置当前窗体所有控件的Text

    在我们编程的时候,有时需要动态的获取当前窗体控件的Text,但是又不能一个一个控件的设置,这个时候可以通过反射来动态设置. 第一步:先建立一个类来保存控件的Text信息. public class C ...