COCI '07 Contest 3 #5 Cudak

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 0.6s
Memory limit: 32M

Problem type

Božo is a strange little boy. Every day he tires his friends with strange questions. Today's question is: how many integers in the interval [A, B] are there such that the sum of their digits is S, and which is the smallest such number?

Write a program that answers Božo's question so that he can get some sleep.

Input Specification

The input contains three integers A, B and S (1 \le A \le B < 10^{15}, 1 \le S \le 135).

Output Specification

The first line should contain the number of integers in the interval with the digit sum equal to S. The second line should contain the smallest such integer. The input data will guarantee that the first number is at least 1.

Scoring

For correctly outputting one of the two numbers you will receive 50\% of the score.

Note: if you want to receive credit for just the second number, be sure to output something (0, for example) as the first number so the judge can interpret your output correctly.

Sample Input 1

1 9 5

Sample Output 1

1
5

Sample Input 2

1 100 10

Sample Output 2

9
19

Sample Input 3

11111 99999 24

Sample Output 3

5445
11499

Comments


  • 0
    thanhtrongdo45  commented on Nov. 9, 2023, 10:07 a.m.

    How to outputting correctly ?

    My output is clearly similar to the answer

    In test 01:

    This output has 0 point

    22
    106

    But this output has 50 points

    22
    
    106

  • 4
    Plasmatic  commented on Nov. 14, 2018, 11:28 p.m. edit 2

    The test data on this problem is weak, I had a passing solution that would output

    1
    1

    for the data 10 11 1. The correct answer should be

    1
    10

    I have since corrected the mistake in my code though I'm not sure whether my fix works for all cases like that.