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 ;
}

最新文章

  1. 修改Tomcat响应请求时返回的Server内容
  2. POJ 3641 快速幂+素数
  3. SPSS数据分析—非参数检验
  4. 【循序渐进学Python】5.Python常用流程控制及其他语句
  5. 手动删除webapps下项目,导致Document base %TOMCAT_HOME%\webapps\XXX does not exist or is not a readable directory
  6. PLSQL_闪回操作5_Flashback Table
  7. [HIHO1041]国庆出游(DFS, bitset)
  8. php使用memcache与memcached扩展对key值的影响
  9. Java多态性举例说明
  10. ssh项目访问路径及url请求书写
  11. 调试 smallcorgi/Faster-RCNN_TF 的demo过程遇到的问题
  12. 深入java多线程一
  13. Python + Tornado 搭建自动回复微信公众号
  14. php之swoole安装与基本使用
  15. LeetCode 33 - 搜索旋转排序数组 - [二分]
  16. #WEB安全基础 : HTTP协议 | 0x14 HTTP的详细安全问题
  17. Lodop提示安装或升级的注意事项
  18. 二、Java神经网络框架Neuroph的使用和架构分析
  19. 解决yum安装ftp提示仓库 的 GPG 密钥已安装,但是不适用于此软件包。
  20. okhttp 调用相机 上传服务器

热门文章

  1. Embedded Android 协同翻译
  2. Swift3.0中关于日期类的使用指引
  3. 多个submit
  4. 使用Aliyun Docker 容器镜像/注册表服务
  5. 大数据攻城狮之Linux基础------rpm软件管理
  6. Vue.js和Nodejs的关系
  7. webkitdirectory 实现文件夹上传
  8. WPF使用Winform PDFView控件
  9. myslide探索
  10. 【Oracle】搭建DG(DataGuard)