結果
| 問題 |
No.844 split game
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 15:46:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 1,296 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 82,616 KB |
| 実行使用メモリ | 121,712 KB |
| 最終ジャッジ日時 | 2025-03-26 15:47:15 |
| 合計ジャッジ時間 | 8,721 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 56 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
N = int(input[ptr])
ptr +=1
M = int(input[ptr])
ptr +=1
A = int(input[ptr])
ptr +=1
intervals_by_r = [[] for _ in range(N+2)] # r can be up to N
for _ in range(M):
l = int(input[ptr])
ptr +=1
r = int(input[ptr])
ptr +=1
p = int(input[ptr])
ptr +=1
intervals_by_r[r].append( (l, p) )
dp = [-float('inf')] * (N+1) # since i ranges from 0 to N
dp[0] = 0
current_max = 0 # max dp[j] for j < i
for i in range(1, N+1):
cost = A if i != N else 0
case_b = current_max - cost
case_a = -float('inf')
for (l, p) in intervals_by_r[i]:
j = l -1
if j >=0 and dp[j] != -float('inf'):
temp = dp[j] + p - cost
if temp > case_a:
case_a = temp
dp_i = max(case_a, case_b)
dp[i] = dp_i if dp_i != -float('inf') else 0 # Handle case where both are -inf
if i != N:
if dp[i] > current_max:
current_max = dp[i]
print(max(dp[N], 0)) # Ensure non-negative result as per problem's examples
if __name__ == '__main__':
main()
lam6er