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 ...
随机推荐
- iOS GCD使用指南
Grand Central Dispatch(GCD)是异步运行任务的技术之中的一个. 一般将应用程序中记述的线程管理用的代码在系统级中实现.开发人员仅仅须要定义想运行的任务并追加到适当的Dispat ...
- Android SQLite服务--创建、增删改查
<pre name="code" class="java">import android.content.Context; import andro ...
- 什么是Spark?
什么是Spark Spark是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加高速.Spark很小巧玲珑,由加州伯克利大学AMP实验室的Matei为主的小团队所开发. 使用的语言是Scala ...
- 简单总结static、final、this关键字的使用
在最近看书的过程中,常常遇到static.final.this这三个关键字,不是很明白它们的使用,查阅资料结合实例做了如下总结: 一.static——无需创建对象就可以调用(方法.属性). 1.静态变 ...
- JavaScript或者Jqurey把控件id作为參数来调用
1.JavaScript把控件id作为參数调用 <script type="text/javascript"> function xx(pmba) { document ...
- ACdream 1154 Lowbit Sum (数位DP)
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...
- hdoj--2015--偶数求和(水题)
偶数求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- NEU操作系统实验课4——线程同步
实验要求: 创建两个线程按数字顺序打印10以下自然数,其中一个线程打印1-3及8-10:另一个线程打印4-6.要求使用线程同步机制实现上述打印顺序. 看网上的资料学习了两种写法 C++11的,使用了s ...
- day63-webservice 07.07.如何修改cxf配置文件路径
为什么第一次访问http://localhost:8080/cxf-web-server/service有点慢?证明第一次访问的时候CXFServlet被初始化了被加载了.一般是让CXFServlet ...
- [jzoj 6073] 河 解题报告 (DP)
interlinkage: https://jzoj.net/senior/#main/show/6073 description: solution: 考虑一条河$x$被染的效果 显然对于一条河$i ...