Блог пользователя asim2005

Автор asim2005, 3 года назад, По-английски

https://codeforces.com/problemset/problem/903/A

In the tutorial, they are saying "For example, you could just iterate on the values of a and b from 0 to 33 and check if 3a + 7b = x." Why is it 33 and no other number ? Please explain it to me.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You will never need any of a or b to be more than 33.

If a > 33, then the number of chunks these portions will contain will be 3a >= 3*34 > 100. 100 is the maximum value that you can be given, so you never want any more than 33 portions of the first type.

Similarly, if b > 14, then the number of chunks these portions will contain will be 7b >= 7*15 > 100. 100 is the maximum value that you can be given, so you never want any more than 14 portions of the second type.

But these numbers aren't really important. You just have to choose conditions for each loop. For example, you could choose a <= 33 and b <= 14.