Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
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 贪心 + 简单模拟的更多相关文章
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- 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 ...
- 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 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 #274 (Div. 2) C. Exams (贪心)
题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 安装.NET Core 3.0预览版后VS项目目标框架中不显示的解决方法
下载了微软在GitHub上的cSharpSamples项目后发现其中一些项目使用框架为.NET Core3.0,就下载了.NET Core3.0,但发现项目依然不可用,编译时提示如下 当前 .net ...
- Linux下安装二进制版mysql-8.0.15
1.添加用户## 添加用户组groupadd mysql## 添加用户,指定用户home目录useradd -g mysql mysql -d /data/mysql## 解压下载的mysql二进制包 ...
- 网络编程学习笔记-TCP拥塞控制机制
为了防止网络的拥塞现象,TCP提出了一系列的拥塞控制机制.最初由V. Jacobson在1988年的论文中提出的TCP的拥塞控制由“慢启动(Slow start)”和“拥塞避免(Congestion ...
- ZOJ1905Power Strings (KMP||后缀数组+RMQ求循环节)
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- poj1417 True Liars[并查集+背包]
有一点小转化的题,在设计dp状态时还是有点费脑筋的. 地址. 依题意,首先可以知道肯定要扩展域的并查集(明摆着的嘛).一个"好人"域,一个"坏人"域,每句话分两 ...
- java计算两个时间相差(天、小时、分钟、秒)
public static Long dateDiff(String startTime, String endTime, String format, String str) { // 按照传入的格 ...
- gitea (git服务器), 修改配置,更换IP地址
使用的gitea项目管理git 服务器 (可以不用备份项目, 通过直接修改gitea配置, 直接使用) 步骤1 可以直接访问项目, 步骤2 ,如果已有项目IP地址固定为192.168.1.x, 新的I ...
- leetcode Word Break-单词划分
题目描述: 给定一个字符串s和一组单词,确定这个字符串是否能够进行这样一种划分,划分后所有的子字符串均来自给定的单词组.例如s = “leetcode” ,dict = {“leet”,“code”} ...
- 开源.Net项目合集
http://www.cnblogs.com/StrangeCity/p/OpenSourceProject.html
- Connection reset by peer的常见原因及解决办法
转自:https://blog.csdn.net/xc_zhou/article/details/80950753 1,如果一端的Socket被关闭(或主动关闭,或因为异常退出而 引起的关闭),另一端 ...