链接:

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)的更多相关文章

  1. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  2. Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)

    因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...

  3. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  4. codeforces Round #568(Div.2)A B C

    有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...

  5. Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)

    第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...

  6. Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治

    题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...

  7. Codeforces Round #568 (Div. 2) 选做

    A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...

  8. Codeforces Round #555 (Div. 3) c2 d e f

    c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...

  9. Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】

    一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...

随机推荐

  1. Altera DDR2 IP核学习总结2-----------DDR2 IP核的生成

    打开IP核工具,然后选择Verilog HDL选项,填写路径,写入文件名DDR2_IP.V,点击next PLL reference clock frequency填入板子晶振的频率50MHZ,这里设 ...

  2. 关于多线程efcore dbcontext 的解决方案。

    首先我们大部分的efcore框架用的DbContext(或者封装的repo)都是底层注入的上下文容器实体. 然后Dbcontext不是线程安全的,也就是说,你在当前线程中,只能创建一个 DbConte ...

  3. vue ----》实现打印功能

    1.安装打印相关依赖 cnpm install vue-print-nb --save 2.安装后,在main.js文件中引入 import Print from 'vue-print-nb' Vue ...

  4. Akka系列(九):Akka分布式之Akka Remote

    前言.... Akka作为一个天生用于构建分布式应用的工具,当然提供了用于分布式组件即Akka Remote,那么我们就来看看如何用Akka Remote以及Akka Serialization来构建 ...

  5. vs2015中将复制过来的文件夹显示目录文件

    先将文件夹和文件复制到VS程序所在的位置,点击解决方案资源管理器上的“显示所有文件”按纽,展开这个文件夹,这样你就可以看到这个文件或者文件夹了,这时,这个文件或者文件夹是虚线构成的.你右击这个文件或者 ...

  6. CAN 总线数据收发驱动

    目标:使用链表实现 CAN 总线数据的分帧发送和分帧数据的接收,同时将接收到的多帧数据合并成一个完整的数据包. 使用场合:当一个CAN总线网络上有多个端口对同一个端口发送分帧数据,且来自不同端口的分帧 ...

  7. 洛谷 P1809 过河问题 题解

    题面 这道题是一道贪心+DP的好题: 首先排序是一定要干的事情. 然后我们分情况处理: 1.如果剩一个人,让最小的回来接他 2.如果剩两个人,让最小的回来接,剩下的那两个人(即最大的两个人)过去,让次 ...

  8. list 小练习

    li = ["alex", "WuSir", "ritian", "barry", "wenzhou" ...

  9. python 利用 smtplib发邮件

    import smtplib from email.mime.text import MIMEText title = "request build error" content ...

  10. 学习WCF之路,长期更新

    我学习WCF之路:创建一个简单的WCF程序   为了使读者对基于WCF的编程模型有一个直观的映像,我将带领读者一步一步地创建一个完整的WCF应用.本应用功能虽然简单,但它涵盖了一个完整WCF应用的基本 ...