题意:一个人买游戏,游戏购买顺序是从左到右的,给n个游戏,他的钱包里有m张钞票,每张都有 一定的面值,,如果当前面值能够买游戏,就会买游戏,然后钞票用掉。不能购买就跳下张钞票,直到能够买为止。输出最多能购买多少游戏。
题解:模拟
#include<bits/stdc++.h>
using namespace std;
int a[1010],c[1010],n,m,j;
int main()
{
cin>>n>>m;
for(int i=0; i<n; i++)
cin>>c[i];
for(int i=0; i<m; i++)
cin>>a[i];
for(int i=0; i<n; i++)
if(c[i]<=a[j])
j++;
cout<<j<<endl;
return 0;
}
python:
n,m=map(int,input().split())
c=list(map(int,input().split()))
a=list(map(int,input().split()))
j=0
for i in c:
if j<m and i<=a[j]:
j+=1
print(j)