HDU 2439 The Mussels
The Mussels
This problem will be judged on HDU. Original ID: 2439
64-bit integer IO format: %I64d Java class name: Main
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
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
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的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- HDU 2255 奔小康赚大钱 KM算法题解
KM算法求的是完备匹配下的最大权匹配,是Hungary算法的进一步,由于Hungary算法是最大匹配的算法,不带权. 经典算法,想不出来的了,要參考别人的.然后消化吸收吧. 由于真的非常复杂的算法. ...
- 屏幕測试亮点,新买了一个显示器,使用web简单的測试下了亮点
1,购买了一个新的显示器 趁着双11的时候价格廉价.入手了一个显示器. http://serve.netsh.org/pub/dead_pixel.bin 滚动下就能够换颜色了.把chrome最大化, ...
- luogu1226 取余运算||快速幂
题目大意:快速求$a^b\mod p$的值. 根据二进制,令$b=\sum t_k\cdot 2^k, t\in \{0,1\}$,那么$$a^b=a^{\sum t_k\cdot 2^k}\mod ...
- Android开机动画、logo、字样的定制过程【转】
本文转载自:http://blog.csdn.net/yinhaide/article/details/43668401 Android开机画面总共有三屏 一.第一屏:开机logo 1.选张png格式 ...
- Patterns in the Composite Application Library
Patterns in the Composite Application Library Inversion of Control https://www.codeproject.com/Artic ...
- Linux系统查看当前时间的命令
转自:https://www.cnblogs.com/redfire/p/7702213.html 一.查看和修改Linux的时区1. 查看当前时区命令 : "date -R"2. ...
- C Linux read write function extension
前言 - 赠送 readn / writen Linux 上默认的 read 和 write 函数会被信号软中断. 且 read 和 write 函数中第三个参数 count #include < ...
- 浅谈Python Web 框架:Django, Twisted, Tornado, Flask, Cyclone 和 Pyramid
Django Django 是一个高级的 Python Web 框架,支持快速开发,简洁.实用的设计.如果你正在建一个和电子商务网站相似的应用,那你应该选择用 Django 框架.它能使你快速完成工作 ...
- 全局变量变为局部变量 & MVC思想
1 函数中的全局变量如何变成局部变量? 全局变量之间会相互骚扰.所以在代码中不要用全局变量.ES6之前只有函数里面有全局变量. 全局变成局部变量怎么变? 把代-放在一个函数如中,再.call()执行一 ...
- Codeforces Round #453
Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...