[CodeForces - 1009A]Game Shopping

Portal problem_link.

Very simple reading problems, mainly to understand the meaning of the questions: N give you a game, the price of each game is Ci. After you give money to M copies, each money is Ai.

Note: The money is spent in order to have a next, like a second sample, 19 games can not buy anything, so the money can not be used next, so that 0 parts

hint: Analog to queue

#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

 

Guess you like

Origin www.cnblogs.com/Vikyanite/p/11368528.html