Milk Pails

问题描述

USACO 2016 February Contest, Bronze Problem 1. Milk Pails https://usaco.org/index.php?page=viewproblem2&cpid=615

给定 X,Y,MX, Y, M ,求 aX+bYaX + bY 不超过 MM 的最大值,a,ba, b 任意。

样例

输入

17 25 77

输出

76

思路

aa 的范围为 00M/XM/Xbb 的范围为 00M/YM/Y 。 遍历 aabb ,如果 aX+bYaX + bY 不超过 MM ,则 ansans 更新为最大值。

代码

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("pails.in", "r", stdin);
    freopen("pails.out", "w", stdout);
    int x, y, m;
    cin >> x >> y >> m;
    int ans = 0;
    for(int i = 0; i <= m / x; i++){
        for(int j = 0; j <= m / y; j++){
            int now = i * x + j * y;
            if(now <= m){
                ans = max(now, ans);
            }
        }
    }
    cout << ans;
    return 0;
}

Milk Pails
https://mingsm17518.github.io/2026/04/30/算法学习/03_Bronze/01_Complete_Search/01_Milk Pails/
作者
Ming
发布于
2026年4月30日
更新于
2026年9月13日
许可协议