链接:

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. Redis 5.0

    1.概述默认端口号:6379 redis是一种nosql数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,并且他比memcached支持更多的数据结构(s ...

  2. 从AWSome Day你可以学到什么?

    前言: AWS中国资深技术专家将带领你循序渐进的了解AWS主要核心服务,包括:计算(Compute).存储(Storage).数据库(Database).网络(Networking)以及安全性(Sec ...

  3. 【HANA系列】SAP ECLIPSE中创建ABAP项目的步骤

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP ECLIPSE中创建AB ...

  4. [转帖]vCenter 计划任务.

    vSphere5.0实用小技巧-DPM计划任务 2013年05月12日 23:00:09 weixin_34185320 阅读数:9 https://blog.csdn.net/weixin_3418 ...

  5. multiplication_puzzle(区间dp)

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. 使用render函数渲染组件

    使用render函数渲染组件:https://www.jianshu.com/p/27ec4467a66b

  7. C++中的异常处理(上)

    1,C++ 内置了异常处理的语法元素 try ... catch ...: 1,try 语句处理正常代码逻辑: 2,catch 语句处理异常情况: 3,try 语句中的异常由对应的 catch 语句处 ...

  8. selenium获取微博用户粉丝数

    selenum的安装 selenium文档 获取微博用户粉丝数 from selenium import webdriver from time import sleep wd = webdriver ...

  9. const关键字 C与C++分析

    1 C与C++的区别 1.1.C允许定义两个变量名相同的变量,而C++不允许. 在C语言中是允许定义两个名字相同的全局变量.  在C++中是不允许定义两个名字相同的全局变量. 测试代码: /* 编译环 ...

  10. C#获取主机信息

    获取主机信息 最近需要做一个配合集控系统收集各个终端设备的一些信息,大致需要收集终端设备的硬件信息,CPU.内存以及硬盘使用率等信息.网上查看了一番,使用WMI来获取这些信息是最方便的.实现代码如下: ...