链接:

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版本。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = 2e7 + 10;
  5. const int MOD = 1e9 + 7;
  6. int n, m, k, t;
  7. int Num[MAXN];
  8. int main()
  9. {
  10. cin >> n >> m;
  11. int sum = 0, v, cnt;
  12. for (int i = 1;i <= n;i++)
  13. {
  14. cnt = 0;
  15. int tmp = sum;
  16. cin >> v;
  17. if (m - sum < v)
  18. {
  19. for (int j = 100;j >= 1;j--)
  20. {
  21. if (m - (tmp-j*Num[j]) >= v)
  22. {
  23. cnt += (tmp-m+v+j-1)/j;
  24. break;
  25. }
  26. tmp -= j*Num[j];
  27. cnt += Num[j];
  28. }
  29. }
  30. cout << cnt << ' ' ;
  31. Num[v]++;
  32. sum += v;
  33. }
  34. cout << endl;
  35. return 0;
  36. }

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. mysql linux环境

    创建新用户 create user jnroot@'%' identified by 'Yc@edc#sJn';创建数据库 create database price_monitor DEFAULT ...

  2. JS BOM(浏览器对象)

    BOM即浏览器对象模型,它包括如下一些对象! (一)screen对象,Screen 对象中存放着有关显示浏览器屏幕的信息. 常见的属性有: availHeight:返回显示屏幕的高度 availWid ...

  3. java:Cookie(常用操作),Cookie和Session免登录实例

     1.常用操作: package cn.zzsxt.lee.web.cookie; import java.io.IOException; import javax.servlet.ServletEx ...

  4. [转载]jsp上传文件

    JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图像文件或任何文档. 本章节我们使用 Servlet 来处理文件上传,使用到的文件有: uplo ...

  5. C#学习笔记三(委托·lambda表达式和事件,字符串和正则表达式,集合,特殊的集合)

    委托和事件的区别 序号 区别 委托 事件 1 是否可以使用=来赋值 是 否 2 是否可以在类外部进行调用 是 否 3 是否是一个类型 是 否,事件修饰的是一个对象 public delegate vo ...

  6. SQL子连接案例

    子查询 何时使用子查询 1. 子查询作为数据源 2. 数据加工 需求:根据不同顾客的所有的账户余额划分区间,进行分组 sql语句实现如下: select 'Small Fry' name , 0 lo ...

  7. XSS-存储型

    @实操视频https://www.bilibili.com/video/av26679456?from=search&seid=13377211289924067562 存储型的注入对象不是搜 ...

  8. https原理以及golang基本实现

    关于https 背景知识 密码学的一些基本知识 大致上分为两类,基于key的加密算法与不基于key的加密算法.现在的算法基本都是基于key的,key就以一串随机数数,更换了key之后,算法还可以继续使 ...

  9. Linux 根据端口快速停止服务并启动的办法

    0. 需要使用 lsof 的命令, 如果linux 上面没有安装的话 需要自行安装 yum install lsof or apt-get install lsof 1. 先根据端口查进程号 [roo ...

  10. Java最新学习线路(基础,源码,项目,实战)

    如需获取以下学习资源请关注公众号:Java编程指南 我们为自学者编程的或初学java的小伙伴们准备了一整套完整的学习资源和文章,还有我自己在自学路上的一些总结和学习线路,希望能帮到小伙伴们,如果有什么 ...