結果

問題 No.1676 Coin Trade (Single)
ユーザー wolgnikwolgnik
提出日時 2021-09-10 22:10:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,549 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 83,360 KB
最終ジャッジ日時 2023-09-02 18:03:40
合計ジャッジ時間 8,697 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,920 KB
testcase_01 AC 73 ms
71,356 KB
testcase_02 AC 76 ms
71,316 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 283 ms
80,600 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 75 ms
71,012 KB
testcase_14 WA -
testcase_15 AC 74 ms
71,176 KB
testcase_16 WA -
testcase_17 AC 76 ms
71,124 KB
testcase_18 AC 76 ms
71,108 KB
testcase_19 WA -
testcase_20 AC 78 ms
70,912 KB
testcase_21 AC 78 ms
70,916 KB
testcase_22 WA -
testcase_23 AC 78 ms
71,180 KB
testcase_24 AC 77 ms
71,120 KB
testcase_25 AC 77 ms
71,164 KB
testcase_26 AC 79 ms
70,924 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 73 ms
71,324 KB
testcase_30 AC 73 ms
71,132 KB
testcase_31 AC 77 ms
71,196 KB
testcase_32 AC 74 ms
71,256 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 311 ms
82,188 KB
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
dp = [0] * (N + 1)
a = [0] * (N + 1)

class SegTree:
  def segfunc(self, x, y):
    return max(x, y)
  def __init__(self, n, ide_ele, init_val):
    #####単位元######
    self.ide_ele = ide_ele
    #num:n以上の最小の2のべき乗
    self.num = 2 ** (n - 1).bit_length()
    self.seg = [self.ide_ele] * 2 * self.num
    #set_val
    for i in range(n):
      self.seg[i + self.num - 1] = init_val[i]    
    #built
    for i in range(self.num - 2, -1, -1) :
      self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
  def update(self, k, x):
    k += self.num - 1
    self.seg[k] = x
    while k + 1:
      k = (k - 1) // 2
      self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) 
  def query(self, p, q):
    if q <= p:
      return self.ide_ele
    p += self.num - 1
    q += self.num - 2
    res = self.ide_ele
    while q - p > 1:
      if p & 1 == 0:
        res = self.segfunc(res, self.seg[p])
      if q & 1 == 1:
        res = self.segfunc(res, self.seg[q])
        q -= 1
      p = p // 2
      q = (q - 1) // 2
    if p == q:
      res = self.segfunc(res, self.seg[p])
    else:
      res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
    return res

seg = SegTree(N + 1, 0, [0] * (N + 1))
for i in range(1, N + 1):
  x, m = map(int, input().split())
  a[i] = x
  b = list(map(int, input().split()))
  for j in b: seg.update(i, max(seg.query(i, i + 1), seg.query(0, j) + x - a[j]))
print(seg.query(0, N + 1))
0