結果
| 問題 |
No.2182 KODOKU Stone
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-30 22:40:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,906 bytes |
| コンパイル時間 | 483 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 124,956 KB |
| 最終ジャッジ日時 | 2024-11-25 21:14:55 |
| 合計ジャッジ時間 | 10,175 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 3 RE * 2 |
ソースコード
import sys
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
from collections import deque
import bisect
import heapq
class Heap():
def __init__(self, maxi = False):
self.sum = 0
self.al = []
self.maxi = maxi
self.len = 0
def __len__(self):
return len(self.al)
def add(self, x):
if self.maxi:
heapq.heappush(self.al, -x)
else:
heapq.heappush(self.al, x)
self.sum += x
def pop(self):
if self.maxi:
now = heapq.heappop(self.al)
self.sum += now
return -now
else:
now = heapq.heappop(self.al)
self.sum -= now
return now
def top(self):
now = self.pop()
self.add(now)
return now
n = ii()
k = li()
a = []
for _ in range(n):
_ = ii()
a.append(list(sorted(li())))
def check(x):
p = []
q_max = 0
for v in a:
gt = len(v) - bisect.bisect(v, x)
if gt < len(v):
p.append(gt)
elif q_max < gt:
q_max = gt
if not p:
return True
p.sort()
que = Heap()
for v in k[len(p):]:
que.add(v)
if(que and q_max >= que.top()):
return True
for i in range(len(p) - 1, -1, -1):
u = k[i] if len(que) == 0 else min(que.top(), k[i])
if(p[i] >= u):
return True
elif(p[i] < u - 1):
return False
elif(len(que) and p[i] == que.top() - 1 and q_max >= k[i]):
return True
elif(i == 0):
return False
elif(len(que) == 0 or p[i] < que.top() - 1):
continue
que.pop()
que.add(k[i])
return True
A = []
for i in range(n):
for v in a[i]:
A.append(v)
A = list(set(A))
A.sort()
ok = 0
ng = len(A)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(A[mid]):
ok = mid
else:
ng = mid
print(A[ok+1])