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. sql格式化日期

    SELECT CONVERT(date, GETDATE()) ---- SELECT CONVERT(varchar(), GETDATE(), ) ----

  2. [iOS]UITableViewController完毕收回键盘操作

    UITableViewController 本身可以实现键盘适配(cell中控件焦点会移动到键盘上方 在做键盘收回的时候思考过例如以下方案 1.tableview加入点击事件 结果:点击事件和tabl ...

  3. 【C++/数据结构】顺序表的基本操作

    <span style="font-size:18px;"><strong>#pragma once #include <iostream> u ...

  4. 0x58 数据结构优化DP

    补写一下 poj3171 设f[i]表示覆盖L~i的最小花费,把区间按左端点排序,枚举区间,f[a[i].r]=min{f[a[i].l~(a[top].r-1)]}+a[i].c (当然还要和原值比 ...

  5. hdu 1002(大数)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 1257(最小拦截系统)

    Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不 能超过前一发的高度.某天,雷达 ...

  7. Linux系统查看当前时间的命令

    转自:https://www.cnblogs.com/redfire/p/7702213.html 一.查看和修改Linux的时区1. 查看当前时区命令 : "date -R"2. ...

  8. Android GoogleMap 谷歌地图从零开始

    说明 由于国内使用v2最新的谷歌地图有很多限制,所有如果要在真机上测试运行要做一些准备 准备1: vpn必不可少啦 推荐cloud vpn或者betternet都是不错的免费vpn 准备2: 由于最新 ...

  9. LCA 离线的Tarjan算法 poj1330 hdu2586

    LCA问题有好几种做法,用到(tarjan)图拉算法的就有3种.具体可以看邝斌的博客.http://www.cnblogs.com/kuangbin/category/415390.html 几天的学 ...

  10. Nginx配置Q&A

    隐藏响应头 How can remove Nginx from http response header? - Stack Overflow more_set_headers 'Server: my- ...