A. Game Shopping

题目链接

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

题解

简单题。题意大概是用一组钱买一组商品,用当前这张钱购买当前这个商品,买不起则尝试下一个商品,买得起则这张钱消失(不管有无剩余),用下一张钱尝试下一个商品。
直接按照题意模拟操作即可。

代码

#include <iostream>
#include <algorithm>
using namespace std;

int n, m, a[1005], c[1005], lc(1), la(1), ans(0);
int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)cin >> c[i];
    for (int i = 1; i <= m; i++)cin >> a[i];
    while (lc <= n && la <= m) {
        if (c[lc] <= a[la]) {
            ans++;
            lc++;
            la++;
        }
        else lc++;
    }
    cout << ans;
}

标签: implementation

添加新评论