結果
問題 | No.844 split game |
ユーザー |
![]() |
提出日時 | 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 sysinput = sys.stdin.read().split()ptr = 0N = int(input[ptr])ptr +=1M = int(input[ptr])ptr +=1A = int(input[ptr])ptr +=1intervals_by_r = [[] for _ in range(N+2)] # r can be up to Nfor _ in range(M):l = int(input[ptr])ptr +=1r = int(input[ptr])ptr +=1p = int(input[ptr])ptr +=1intervals_by_r[r].append( (l, p) )dp = [-float('inf')] * (N+1) # since i ranges from 0 to Ndp[0] = 0current_max = 0 # max dp[j] for j < ifor i in range(1, N+1):cost = A if i != N else 0case_b = current_max - costcase_a = -float('inf')for (l, p) in intervals_by_r[i]:j = l -1if j >=0 and dp[j] != -float('inf'):temp = dp[j] + p - costif temp > case_a:case_a = tempdp_i = max(case_a, case_b)dp[i] = dp_i if dp_i != -float('inf') else 0 # Handle case where both are -infif i != N:if dp[i] > current_max:current_max = dp[i]print(max(dp[N], 0)) # Ensure non-negative result as per problem's examplesif __name__ == '__main__':main()