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