結果

問題 No.2617 容量3のナップザック
ユーザー とりゐとりゐ
提出日時 2024-01-26 22:05:51
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 814 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 191,868 KB
最終ジャッジ日時 2024-01-26 22:05:56
合計ジャッジ時間 4,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
60,264 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 40 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 39 ms
53,460 KB
testcase_09 AC 39 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 39 ms
53,460 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K,seed,a,b,m=map(int,input().split())
w=[0]*N
f=seed
for i in range(N):
  w[i]=f%3+1
  f=(a*f+b)%m

v=[0]*N
for i in range(N):
  v[i]=f*w[i]
  f=(a*f+b)%m

w1=[0]*3*K
w2=[0]*K
w3=[0]*K
for i in range(N):
  if w[i]==1:
    w1.append(v[i])
  if w[i]==2:
    w2.append(v[i])
  if w[i]==3:
    w3.append(v[i])

w1.sort(reverse=True)
w2.sort(reverse=True)
w3.sort(reverse=True)

ans=0
res=[0]
idx1=0
idx2=0
tmp=0
for i in range(1,K+1):
  tmp+=w1[idx1]+w1[idx1+1]+w1[idx1+2]
  idx1+=3
  while idx2<i and w2[idx2]>=w1[idx1-1]+w1[idx1-2]:
    tmp+=w2[idx2]-w1[idx1-1]-w1[idx1-2]
    idx2+=1
    idx1-=2
  while idx2>0 and w1[idx1]+w1[idx1+1]>=w2[idx2-1]:
    tmp+=w1[idx1]+w1[idx1+1]-w2[idx2-1]
    idx2-=1
    idx1+=2
  res.append(tmp)

cum3=0
for i in range(K+1):
  ans=max(ans,res[K-i]+cum3)
  cum3+=w3[i]

print(ans)
0