31 lines
741 B
C++
31 lines
741 B
C++
#include <iostream>
|
|
#include <fstream>
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
std::ifstream inputFile(argv[1]);
|
|
|
|
int boxSize, goldSize, goldValue, silverSize, silverValue;
|
|
|
|
while (inputFile >> boxSize >> goldSize >> goldValue >> silverSize >> silverValue)
|
|
{
|
|
int maxValue = 0;
|
|
int goldCount = boxSize / goldSize;
|
|
int silverCount = boxSize / silverSize;
|
|
|
|
for (size_t i = 0; i <= goldCount; i++)
|
|
{
|
|
for (size_t j = 0; j <= silverCount; j++)
|
|
{
|
|
if (i * goldSize + j * silverSize <= boxSize)
|
|
{
|
|
int value = i * goldValue + j * silverValue;
|
|
maxValue = std::max(maxValue, value);
|
|
}
|
|
}
|
|
}
|
|
printf("%d\n", maxValue);
|
|
}
|
|
inputFile.close();
|
|
return 0;
|
|
} |