asim2005's blog

By asim2005, 4 months ago, In English

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.

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Me too

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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.