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 ...
随机推荐
- windows与Linux操作系统的差别
用户需要记住:Linux和Windows在设计上就存在哲学性的区别.Windows操作系统 倾向于将更多的功能集成到操作系统内部,并将程序与内核相结合:而Linux不同 于Windows,它的内核空间 ...
- Tips:PowerDesigner16.5 图表显示Code以及 Columns新增Commet显示
- 高性能MySQL之【第十六章MySQL用户工具】学习记录
接口工具: Msql Workbench http://www.mysql.com/products/workbench SQLyog http://www.webyog.c ...
- ACM学习历程—HDU 1059 Dividing(dp && 多重背包)
Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...
- ACM学习历程——HDU3333 Turing Tree(线段树 && 离线操作)
Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems abou ...
- ogg概叙、架构、进程
一. OGG 概述 OGG 全称Oracle Golden Gate. 历史: Golden Gate公司于1995年成立于美国加州旧金山,它的名称源自旧金山闻名于世的金门大桥.两位创始人Eric F ...
- .NETFramework-Web.Services:WebMethodAttribute
ylbtech-.NETFramework-Web.Services:WebMethodAttribute 1.程序集 System.Web.Services, Version=4.0.0.0, Cu ...
- JavaScript高级程序设计学习笔记第四章--变量、作用域和内存问题
1.变量可能包含两种不同数据类型的值:基本类型值和引用类型值. 基本类型值指的是简单的数据段,而引用类型值指那些可能由多个值构成的对象. 2.变量复制 如果从一个变量向另一个变量复制基本类型的值,会在 ...
- c# 正则表达式移除html文本前面的空格
var val = Regex.Replace(text, @"^( | )+(?<value>.*)", "${value}", RegexOpt ...
- wpf窗口禁止最大化但允许调整大小
wpf中窗口禁止最大化可以通过属性ResizeMode来设置,但是ResizeMode有一个问题就是如果ResizeMode设置为NoResize的话,是可以禁止最大化的,但是这样同时也就不能拖动调整 ...