Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)
链接:
https://codeforces.com/contest/1185/problem/C2
题意:
The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
The i-th student randomly chooses a ticket.
if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
if the student finds the ticket easy, he spends exactly ti minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (maxti≤M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i1 some student j should leave, then while finding the answer for i2 (i2>i1) the student j student does not have to go home.
思路:
c1和c2范围不同,就只写一个c2了
每次循环从100-1的数找有几个,优先用掉最大的就行,原本以为过不了hard版本。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e7 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
int Num[MAXN];
int main()
{
cin >> n >> m;
int sum = 0, v, cnt;
for (int i = 1;i <= n;i++)
{
cnt = 0;
int tmp = sum;
cin >> v;
if (m - sum < v)
{
for (int j = 100;j >= 1;j--)
{
if (m - (tmp-j*Num[j]) >= v)
{
cnt += (tmp-m+v+j-1)/j;
break;
}
tmp -= j*Num[j];
cnt += Num[j];
}
}
cout << cnt << ' ' ;
Num[v]++;
sum += v;
}
cout << endl;
return 0;
}
Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)的更多相关文章
- Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...
- Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)
因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)
第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...
- Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治
题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...
- Codeforces Round #568 (Div. 2) 选做
A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...
- Codeforces Round #555 (Div. 3) c2 d e f
c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
随机推荐
- CentOS7上安装配置破解Elasticsearch+Kibana 6.4.2-6.5.1全过程
最近正在学习服务器应用平台的搭建的相关知识.有幸从朋友与书上了解到Elastic套件的使用,我花了两天的时间把最新的套件部署在我的服务器上,中间踩了数不清的坑.我把整个过程都记录了下来与各位有需要的朋 ...
- VGA显示正圆
接着上次的随笔,既然VGA时序已经实现了,那么就显示点东西看看吧. 想显示个圆,但是无从下手,参考了这篇文章:https://user.qzone.qq.com/1241003385/blog/154 ...
- java高斯消元模板
//package fuc; import java.io.PrintStream; import java.math.BigInteger; import java.util.Scanner; pu ...
- 安装docker registry
docker pull registry 创建目录 /usr/local/docker/registry 创建 docker-compose.yml version: '3' services: r ...
- awk 控制语句if-else
语法: 一.if (条件){语句}[else 语句] 单分支 二.if (条件){语句}else if( 条件){语句} 多分支 示例: .[root@localhost ~]# awk -F: '{ ...
- Spring源码阅读环境搭建
目录 安装gradle 导入Spring源码 创建测试模块my-test 其他问题 spring-aspects模块构建时报错 本文思维导图 本文将粗略的搭建一个Spring源码的阅读环境,为后面的源 ...
- 通过U盘或CD/DVD装centos7,出现“dracut-initqueue timeout..."解决办法
1.在用CD/DVD挂载centos7镜像安装系统时,出现“dracut-initqueue timeout...", :/# cd dev :/# ls 2.这是因为安装程序未能找到安装文 ...
- day 14 装饰器
装饰器:装饰,装修,房子就可以住,如果装修,不影响你住,而且体验更加,让你生活中增加了很多功能:洗澡,看电视,沙发.器:工具.开放封闭原则:开放:对代码的拓展开放的, 更新地图,加新枪,等等.封闭:对 ...
- Codeforces 1215F. Radio Stations
传送门 题目看一半:"woc 裸的 $2-sat$ 白给??" 看完以后:"...???" 如果没有 $f$ 的限制,那就是个白给的 $2-sat$ 问题,但是 ...
- [React] react-interview-01
1.render 函数中 return 如果没有使用()会有什么问题? 我们在使用 JSX 语法书写 react 代码时,babel 会将 JSX 语法编译成 js,同时会在每行自动添加分号(:),如 ...