結果
問題 | No.2546 Many Arithmetic Sequences |
ユーザー | Shirotsume |
提出日時 | 2023-07-24 01:18:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,532 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 144,616 KB |
最終ジャッジ日時 | 2024-09-26 09:53:41 |
合計ジャッジ時間 | 20,581 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
56,192 KB |
testcase_01 | AC | 52 ms
56,064 KB |
testcase_02 | AC | 83 ms
72,448 KB |
testcase_03 | AC | 454 ms
90,500 KB |
testcase_04 | AC | 746 ms
125,924 KB |
testcase_05 | AC | 641 ms
107,628 KB |
testcase_06 | AC | 249 ms
84,020 KB |
testcase_07 | AC | 366 ms
92,160 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 509 ms
128,256 KB |
testcase_15 | AC | 242 ms
92,448 KB |
testcase_16 | AC | 488 ms
125,056 KB |
testcase_17 | WA | - |
testcase_18 | AC | 402 ms
104,072 KB |
testcase_19 | WA | - |
testcase_20 | AC | 315 ms
99,460 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 616 ms
144,036 KB |
testcase_29 | AC | 615 ms
143,792 KB |
testcase_30 | AC | 617 ms
143,544 KB |
testcase_31 | AC | 627 ms
144,100 KB |
testcase_32 | AC | 622 ms
143,528 KB |
testcase_33 | AC | 52 ms
56,320 KB |
testcase_34 | WA | - |
testcase_35 | AC | 54 ms
56,448 KB |
testcase_36 | AC | 512 ms
143,892 KB |
testcase_37 | RE | - |
testcase_38 | AC | 61 ms
63,232 KB |
ソースコード
import sys, time, random, heapq from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 #https://tjkendev.github.io/procon-library/python/convex_hull_trick/deque.html deq = deque() def check(f1, f2, f3): return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0]) def f(f1, x): return f1[0]*x + f1[1] # add f_i(x) = a*x + b def add_line(a, b): f1 = (a, b) while len(deq) >= 2 and check(deq[-2], deq[-1], f1): deq.pop() deq.append(f1) # min f_i(x) def query(x): while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x): deq.popleft() return f(deq[0], x) n, m = mi() AD = [li() for _ in range(n)] plus = [] minus = [] for a, d in AD: if d > 0: plus.append((a, d)) else: minus.append((a, d)) p = [-inf] * (m + 1) p[0] = 0 plus.sort(key = lambda x: x[1], reverse=True) for a, d in plus: add_line(-d, -2 * a + d) if plus: for i in range(1, m + 1): p[i] = -query(i) * i // 2 q = [-inf] * (m + 1) q[0] = 0 H = [] for a, d in minus: heapq.heappush(H, (-a, d)) for i in range(1, m + 1): a, d = heapq.heappop(H) a = -a q[i] = q[i - 1] + a heapq.heappush(H, (-(a + d), d)) ans = -inf maxi = -1 for i in range(0, m + 1): if ans <= p[i] + q[m - i]: ans = max(ans, p[i] + q[m - i]) maxi = i print(ans) print(m, maxi, file=sys.stderr)