CSES - Putka Open 2015 – 2/6 - Results
Submission details
Task:Pussit
Sender:
Submission time:2015-08-15 12:06:29 +0300
Language:Python3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.09 s1details
#20.12 s2details
#3--3details

Code

#!/usr/bin/env python3

def eka_tasajako(pusseja, palloja):
    for pussia in range(pusseja - 1, 1, -1):
        vajaapusseja = pusseja - pussia
        p = palloja
        while p > 0:
            if p % pussia == 0:
                return pussia
            p -= vajaapusseja
    return None

def laske(pusseja, palloja, halutaan):
    if palloja < pusseja:
        tyhjia_pusseja = pusseja - palloja
        return tyhjia_pusseja + halutaan
    elif palloja == pusseja:
        return halutaan

    # palloja > pusseja

    if palloja % pusseja == 0:
        # voidaan jakaa tasan, ei turhia nostoja
        return halutaan

    if halutaan <= pusseja:
        # nostetaan aina eri pussista, ei huteja
        return halutaan

    min_palloja_per_pussi = palloja // pusseja
    helppoja_nostoja = pusseja * min_palloja_per_pussi
    if halutaan <= helppoja_nostoja:
        return halutaan

    tasapusseja = eka_tasajako(pusseja, palloja)
    if tasapusseja is not None:
        turhia_nostoja_max = pusseja - tasapusseja
    else:
        n_pusseja = palloja % pusseja
        n_minus1_pusseja = pusseja - n_pusseja
        turhia_nostoja_max = n_minus1_pusseja

    return turhia_nostoja_max + halutaan

def main():
    for i in range(int(input())):
        n, m, k = map(int, input().strip().split())
        print(laske(n, m, k))

if __name__ == '__main__':
    main()

Test details

Test 1

Group: 1

Verdict:

input
1000
11 16 2
5 16 15
2 14 14
9 11 1
...

correct output
2
15
14
1
1
...

user output
2
15
14
1
1
...

Test 2

Group: 2

Verdict:

input
1000
1436 3023 1378
4419 4559 3881
115 4220 1440
3556 3152 1653
...

correct output
1378
3881
1440
2057
5312
...

user output
1378
3881
1440
2057
3642
...

Test 3

Group: 3

Verdict:

input
1000
337723917 939459738 544279388
233319567 486500388 164139442
722536320 995223331 969580610
274242146 994174001 844564432
...

correct output
544279388
164139442
1194505265
870263078
547470112
...

user output
(empty)