結果
| 問題 |
No.1248 Kth Sum
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-09 20:57:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 572 bytes |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 82,168 KB |
| 実行使用メモリ | 116,704 KB |
| 最終ジャッジ日時 | 2025-04-09 20:58:58 |
| 合計ジャッジ時間 | 10,688 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 WA * 35 |
ソースコード
n, k = map(int, input().split())
arr = list(map(int, input().split()))
# Sort the array by value, keeping track of their 1-based indices
sorted_arr = sorted([(a, i+1) for i, a in enumerate(arr)], key=lambda x: x[0])
m = n // k
sum_ans = 0
ptr = len(sorted_arr) - 1 # Starting from the end of the sorted array
for i in range(1, m + 1):
required_pos = n - (i * k) + 1
while ptr >= 0:
if sorted_arr[ptr][1] >= required_pos:
sum_ans += sorted_arr[ptr][0]
ptr -= 1
break
else:
ptr -= 1
print(sum_ans)
lam6er