ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2025. Line Fighting

AC on python 3.6
Posted by ivan pasechnik`~ 18 Dec 2018 19:24
t = int(input())
for i in range(t):
    m = []
    kv = 0
    n,k = map(int,input().split())
    ok =k
    for i in range (k):
        if i == 0:
            m.append(n//ok)
            kv += m[i]
            n-=n//ok
            ok-=1
        else:
            if i == k-1:
                m.append(n)
            else:
                m.append(n//ok)
                kv+=m[i]
                n-=n//ok
                ok-=1
    otr,ans = 0,0
    l,l1 = 0,0
    m.sort()
    m.reverse()
    ss = sum(m)
    for i in range(k-1):
        l += m[i]
        l1 = m[i]
        ans += (ss-l)*l1
    print(ans)
AC on python 3.6
Posted by Mapu 19 Aug 2019 22:05
t = int(input())
for i in range(t):
    n, k = [int(i) for i in input().split()]
    m = n // k
    q = n % k
    s = (m * (n - m) * (k - q) + (m + 1) * (n - m - 1) * q) // 2
    print(s)

#распределяем максимально равномерно и "деремся" команда из m против всех оставшихся + команда из m + 1 против всех оставшихся и, поскольку учли каждый бой по два раза (для обоих участников), делим пополам =)