The Mussels

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 2439
64-bit integer IO format: %I64d      Java class name: Main

 
"To be or not to be, that is the question." Now FJ( Frank&John) faces a serious problem.

FJ is breeding mussels these days. The mussels all want to be put into a culturist with a grade no little than their own grades. FJ accept their requirements.

FJ provides culturists of different grades, all having a certain capacity. FJ first put mussels into culturists with the same grade until they are full. Then he may put some mussels into some potential culturists that still have capacity.

Now, FJ wants to know how many mussels can be put into the culturists.

 

Input

For each data set:
The first line contains two integers, n and m(0<n<=100000,0<m<=1000000), indicating the number of culturists and the number of mussels. The ith culturist has a grade i, and grade 1 is considered the highest.

The second line contains n integers indicating the culturists' capacity in order.

The third line contains m integers all in the range 1~n, indicating the mussels' grade in order.

Proceed to the end of file.

 

Output

A single integer, which is the number of mussels that can be put into the culturists.

 

Sample Input

4 4
100 4 4 4
1 2 3 4
4 3
1 1 1 1
4 2 2

Sample Output

4
3

Source

 
解题:贪心+模拟,直接按照题目意思去做就是了。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
int cul[],tmp,n,m;
void myscanf(int &x){
char ch;
while((ch = getchar()) < '' || ch > '');
x = ;
x = x* + ch - '';
while((ch = getchar()) >= '' && ch <= '') x = x* + ch - '';
}
int main() {
while(~scanf("%d %d",&n,&m)){
for(int i = ; i <= n; i++)
myscanf(cul[i]);
int ans = ;
for(int i = ; i <= m; i++){
myscanf(tmp);
if(cul[tmp]){
--cul[tmp];
++ans;
}else{
for(int j = tmp; j; --j){
if(cul[j]){
--cul[j];
++ans;
break;
}
}
}
}
printf("%d\n",ans);
}
return ;
}

HDU 2439 The Mussels的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. Selenium webdriver-UI Element定位

    转:http://blog.csdn.net/jillliang/article/details/8206402 1.创建Fixfox web driver实例 WebDriver driver =  ...

  2. hdoj--2767--Proving Equivalences (scc+缩点)

    Proving Equivalences Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other ...

  3. 【Codeforces 258A】 Game With Sticks

    [题目链接] http://codeforces.com/contest/451/problem/A [算法] 若n和m中的最小值是奇数,则先手胜,否则后手胜 [代码] #include<bit ...

  4. 配置Windows群集

    故障转移群集 l  一个群集支持8个节点,(64位操作系统支持16个节点) l  可以使用故障转移群集的服务:SQL Server(数据库), Exchange(邮件),文件和打印服务,DHCP服务等 ...

  5. thinkphp实现多数据库操作

    这篇文章主要介绍了ThinkPHP实现多数据库连接的解决方法,需要的朋友可以参考下   ThinkPHP实现连接多个数据的时候,如果数据库在同一个服务器里的话只需要这样定义模型: ? 1 2 3 cl ...

  6. CTF-Mayday

    打开下载的Mayday.txt文件: 温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 知足温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 知足温柔 知足突然好想你  拥抱突然好想你  拥抱温柔 ...

  7. HTML网页做成ASP.NET后台的方法以及.NET后台控制前台样式的方法

    之前一直不知道,写好的纯HTML网页怎么做成ASP.NET后台的呢,因为之前使用别人的HTML模板写过一个自己的个人博客 果冻栋吖个人博客 当时用的PHP写的.一直在考虑怎么做成.NET的. 今天自己 ...

  8. 企业级Spring应用的搭建

    本次博客将要对SpringMVC做简单的介绍以及环境的搭建: 概述 Spring 框架是一个开源的平台,属于设计层面框架,整个系统面向接口,是分层的JavaSE/EE开源框架,用于解决复杂的企业应用开 ...

  9. Appium 环境搭建 - macOS

    本文没有安装 Appium Desktop,Appium Server 直接在命令行中进行即可. Homebrew,macOS 包管理器: ruby -e "$(curl -fsSL htt ...

  10. 杭电1003 Max Sum 【连续子序列求最大和】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...