问题 C: Frosh Week

时间限制: 4 Sec  内存限制: 128 MB
提交: 145  解决: 63
[提交][状态][讨论版][命题人:admin]

题目描述

Professor Zac is trying to finish a collection of tasks during the first week at the start of the term. He knows precisely how long each task will take, down to the millisecond. Unfortunately, it is also Frosh Week. Zac’s office window has a clear view of the stage where loud music is played. He cannot focus on any task when
music is blaring.
The event organizers are also very precise. They supply Zac with intervals of time when music will not be playing. These intervals are specified by their start and end times down to the millisecond.
Each task that Zac completes must be completed in one quiet interval. He cannot pause working on a task when music plays (he loses his train of thought). Interstingly, the lengths of the tasks and quiet intervals are such that it is impossible to finish more than one task per quiet interval!
Given a list of times ti (in milliseconds) that each task will take and a list of times Lj (in milliseconds) specifying the lengths of the intervals when no music is being played, what is the maximum number of tasks that Zac can complete?

输入

The first line of input contains a pair of integers n and m, where n is the number of tasks and m is the
number of time intervals when no music is played. The second line consists of a list of integers t1,t2,...,tn indicating the length of time of each task. The final line consists of a list of times L1,L2,... ,Lm indicating the length of time of each quiet interval when Zac is at work this week.
You may assume that 1≤n;m≤200,000 and 100,000≤ti,Lj≤199,999 for each task i and each quiet interval j.

输出

Output consists of a single line containing a single integer indicating the number of tasks that Zac can accomplish from his list during this first week.

样例输入

5 4
150000 100000 160000 100000 180000
190000 170000 140000 160000

样例输出

4

很简单的模拟题,开始我想的是存下所有的时间,然后sort,把各自大的放前面,进行比较,虽然担心了时间,但是看到4s还是交了,果不其然t了。Orz

后面一看,不就1e5到2e5的时间范围吗,直接用值哈希,跑一遍。
 #include<bits/stdc++.h>

 using namespace std;

 int task[];
int work_num[];
const int limit = ; int main()
{
int n,m;
scanf("%d%d",&n,&m);
int temp;
memset(task,,sizeof(task));
memset(work_num,,sizeof(work_num));
for(int i=;i<n;i++)
{
scanf("%d",&temp);
task[temp-limit]++;
}
for(int i=;i<m;i++)
{
scanf("%d",&temp);
work_num[temp - limit]++;
}
int ans = ;
int cnt = ;
for(int i=limit;i>=;i--)
{
if(work_num[i])cnt+=work_num[i];
if(cnt != )
{
if(task[i])
{
int minn = min(task[i],cnt);
ans += minn;
cnt -= minn;
}
}
}
printf("%d\n",ans);
} /**************************************************************
Problem: 5129
User: DP18
Language: C++
Result: 正确
Time:68 ms
Memory:2476 kb
****************************************************************/
												

问题 C: Frosh Week(2018组队训练赛第十五场)(签到)的更多相关文章

  1. 问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)

    问题 J: Palindromic Password 时间限制: 3 Sec  内存限制: 128 MB提交: 217  解决: 62[提交][状态][讨论版][命题人:admin] 题目描述 The ...

  2. 备战省赛组队训练赛第十八场(UPC)

    传送门 题解:by 青岛大学 A:https://blog.csdn.net/birdmanqin/article/details/89789424 B:https://blog.csdn.net/b ...

  3. 备战省赛组队训练赛第十六场(UPC)

    传送门 题解: by 烟台大学 (提取码:8972)

  4. 备战省赛组队训练赛第十四场(UPC)

    codeforces:传送门 upc:传送门 外来题解: [1]:https://blog.csdn.net/ccsu_cat/article/details/86707446 [2]:https:/ ...

  5. UPC Contest RankList – 2019年第二阶段我要变强个人训练赛第十五场

    传送门 A: Colorful Subsequence •题意 给一个长为n的小写字母序列,从中选出字母组成子序列 问最多能组成多少种每个字母都不相同的子序列 (不同位置的相同字母也算是不同的一种) ...

  6. UPC个人训练赛第十五场(AtCoder Grand Contest 031)

    传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...

  7. 2018牛客网暑假ACM多校训练赛(第五场)H subseq 树状数组

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-H.html 题目传送门 - https://www.no ...

  8. 2018牛客网暑假ACM多校训练赛(第五场)F take 树状数组,期望

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-F.html 题目传送门 - https://www.no ...

  9. UPC Contest RankList – 2019年第二阶段我要变强个人训练赛第十四场

    A.JOIOJI •传送门 [1]:BZOJ [2]:洛谷 •思路 在一个区间(L,R]内,JOI的个数是相等的,也就是R[J]-L[J]=R[O]-L[O]=R[I]-L[I], 利用前缀和的思想, ...

随机推荐

  1. Jenkins五 配置tomcat

    一:jdk安装 查看系统自带jdk版本并卸载 [root@localhost conf]# rpm -qa|grep jdkjdk1.8-1.8.0_201-fcs.x86_64 移除: yum re ...

  2. 使用Node.js+Hexo+Github搭建个人博客(续)

    一.写在前面 在我的上一篇博客<使用Nodejs+Hexo+Github搭建个人博客>中,已经介绍了如何使用 Hexo 在 Github Pages 上搭建一个简单的个人博客.该篇博文将在 ...

  3. 学习Spring Boot:(一)入门

    微服务 现在微服务越来越火了,Spring Boot热度蹭蹭直升,自学下. 微服务其实是服务化思路的一种最佳实践方向,遵循SOA(面向服务的架构)的思路,各个企业在服务化治理上面的道路已经走得很远了, ...

  4. x学生管理系统(用中间件)-------基于FORM组件

    目的:实现学生,老师,课程的增删改查 models.py from django.db import models # Create your models here. class UserInfo( ...

  5. 论文阅读:Review of Visual Saliency Detection with Comprehensive Information

    这篇文章目前发表在arxiv,日期:20180309. 这是一篇针对多种综合性信息的视觉显著性检测的综述文章. 注:有些名词直接贴原文,是因为不翻译更容易理解.也不会逐字逐句都翻译,重要的肯定不会错过 ...

  6. java子类对象和成员变量的隐写&方法重写

    1.子类继承的方法只能操作子类继承和隐藏的成员变量名字类新定义的方法可以操作子类继承和子类新生命的成员变量,但是无法操作子类隐藏的成员变量(需要适用super关键字操作子类隐藏的成员变量.) publ ...

  7. pycharm提示This inspection detects instance attribute definition outside __init__ method

    示例代码: class MiNiCarStore(CarStore): def createCar(self, typeName): self.carFactory = CarFactory() # ...

  8. 卸载列表信息——Uninstall注册表

    今天用InstallShield打包了一个安装程序,安装顺利完成了,但是当我去控制面板准备卸载时,发现我的程序没有详细的信息,正常的软件信息如下图: 而我的程序没有发布者,大小和版本,也没有图标,于是 ...

  9. MongoDB数据库备份与还原、单表的导入导出

    -------------------MongoDB备份与恢复------------------- 1.MongoDB数据库备份     1.语法:         mongodump -h dbh ...

  10. OpenCV-Python入门教程1-图片

    首先感觉学习OpenCV-python最好的学习工具官方的英文文档. 官方英文教程:OpenCV-Python Tutorials 我使用的是anaconda里的 jupyter notebook.至 ...