1951D - Buying Jewels - CodeForces Solution


constructive algorithms greedy math *2000

Please click on ads to support us..

Python Code:



def solve(budget, count):
    if budget < count:
        return []
    if budget == count:
        return [1]
    if 2 * count > budget + 1:
        return []
    return [budget - count + 1, 1]


if __name__ == '__main__':
    test_count = int(input())
    for _ in range(test_count):
        budget, count = map(int, input().split())
        results = solve(budget, count)
        if results:
            print('YES')
            print(len(results))
            print(' '.join(str(r) for r in results))
        else:
            print('NO')


Comments

Submit
0 Comments
More Questions

844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability
1501A - Alexey and Train
721B - Passwords
1263D - Secret Passwords
1371B - Magical Calendar
1726E - Almost Perfect
1360C - Similar Pairs
900A - Find Extra One
1093D - Beautiful Graph
748A - Santa Claus and a Place in a Class
1511B - GCD Length
676B - Pyramid of Glasses
597A - Divisibility
1632A - ABC
1619D - New Year's Problem
242B - Big Segment
938A - Word Correction