[CodeForces - 1009A]Game Shopping

传送门problem_link.

很简单的阅读题,主要要看懂题意:给你N个游戏,每个游戏的价格是Ci。之后给你M份钱,每份钱是Ai。

注意:钱是花掉一份才能有下一份,就像第二个样例,19块什么游戏都买不了,所以就不能用下一份钱,所以就是0份

hint:队列模拟即可

#include <bits/stdc++.h>
using namespace std;
queue<int> q_game, q_money;
int main()
{
    int n, m, temp;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> temp, q_game.push(temp);
    for (int i = 1; i <= m; i++) cin >> temp, q_money.push(temp);
    int sum = 0;
    while (!q_money.empty() && !q_game.empty())
        if(q_money.front() >= q_game.front()) q_money.pop(), q_game.pop(), sum++;
        else q_game.pop();
    printf("%d\n", sum);
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/Vikyanite/p/11368528.html