結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー ああいい
提出日時 2022-08-07 16:18:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 436 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 98,700 KB
最終ジャッジ日時 2024-09-17 09:33:57
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 16 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

N,S = map(int,input().split())

import sys
if S <= N:
    print(S)
    exit()
M = N * (N + 1) // 2
if M - S <= N:
    ans = []
    for i in range(1,N + 1):
        if i !=~ M - S:
            ans.append(i)
    print(*ans)
    exit()
    
tmp = 0
ans = []
for i in range(N,0,-1):
    if tmp + i <= S:
        ans.append(i)
        tmp += i
    else:
        break
if S - tmp > 0:
    ans.append(S - tmp)
print(len(ans))
print(*ans[::-1])
0