353B - Two Heaps - CodeForces Solution


combinatorics constructive algorithms greedy implementation math sortings *1900

Please click on ads to support us..

Python Code:

def s():
        input()
        l = [[] for _ in range(100)]
        a = list(map(int, input().split()))
        for (i, v) in enumerate(a):
                l[v].append(i)
        c = 0
        cc = 0
        fs = [0, 0]
        for i in l:
                if len(i) == 0:
                        continue
                if len(i) == 1:
                        a[i[0]] = c + 1
                        fs[c] += 1
                        c = 1 - c
                        continue
                fs[c] += 1
                fs[c - 1] += 1
                for e in i[:len(i) // 2]:
                        a[e] = 1 + cc
                for e in i[len(i) // 2:]:
                        a[e] = 2 - cc
                if len(i) % 2 == 1:
                        cc = 1 - cc
        print(fs[0] * fs[1])
        print(*a)
s()


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament