Educational Codeforces Round 47 (Rated for Div. 2) A. Game Shopping

Maxim wants to buy some games at the local game shop. There are
n
games in the shop, the
i
-th game costs
c
i
.

Maxim has a wallet which can be represented as an array of integers. His wallet contains
m
bills, the
j
-th bill has value
a
j
.

Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.

When Maxim stands at the position
i
in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the
i
-th game using this bill. After Maxim tried to buy the
n
-th game, he leaves the shop.

Maxim buys the
i
-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the
i
-th game. If he successfully buys the
i
-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.

For example, for array

c

[
2
,
4
,
5
,
2
,
4
]
and array

a

[
5
,
3
,
4
,
6
]
the following process takes place: Maxim buys the first game using the first bill (its value is
5
), the bill disappears, after that the second bill (with value
3
) becomes the first one in Maxim’s wallet, then Maxim doesn’t buy the second game because
c
2
>
a
2
, the same with the third game, then he buys the fourth game using the bill of value
a
2
(the third bill becomes the first one in Maxim’s wallet) and buys the fifth game using the bill of value
a
3
.

Your task is to get the number of games Maxim will buy.

Input
The first line of the input contains two integers
n
and
m
(
1

n
,
m

1000
) — the number of games and the number of bills in Maxim’s wallet.

The second line of the input contains
n
integers
c
1
,
c
2
,

,
c
n
(
1

c
i

1000
), where
c
i
is the cost of the
i
-th game.

The third line of the input contains
m
integers
a
1
,
a
2
,

,
a
m
(
1

a
j

1000
), where
a
j
is the value of the
j
-th bill from the Maxim’s wallet.

Output
Print a single integer — the number of games Maxim will buy.

Examples
inputCopy
5 4
2 4 5 2 4
5 3 4 6
outputCopy
3
inputCopy
5 2
20 40 50 20 40
19 20
outputCopy
0
inputCopy
6 4
4 8 15 16 23 42
1000 1000 1000 1000
outputCopy
4
Note
The first example is described in the problem statement.

In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.

In the third example the values of the bills in Maxim’s wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.

题目较长,其实很简单,对两个数组扫一遍即可;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define maxn 200005
const int mod=1e9+7;
#define eps 1e-5
#define pi acos(-1.0)

ll quickpow(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1){
            ans=ans*a;
        }
        a=a*a;
        b>>=1;
    }
    return ans;
}
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int c[maxn];
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>c[i];
    for(int i=0;i<m;i++)cin>>a[i];
    int cnt=0;
    int i=0,j=0;
    for(i=0;i<n;i++){
        if(a[j]>=c[i]){
            j++;cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值