結果

問題 No.2698 Many Asakatsu
ユーザー karinohitokarinohito
提出日時 2024-03-16 05:17:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,952 KB
最終ジャッジ日時 2024-03-20 03:04:11
合計ジャッジ時間 10,398 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,600 KB
testcase_01 AC 40 ms
55,600 KB
testcase_02 AC 41 ms
55,600 KB
testcase_03 AC 40 ms
55,600 KB
testcase_04 AC 40 ms
55,600 KB
testcase_05 AC 44 ms
61,140 KB
testcase_06 AC 42 ms
55,600 KB
testcase_07 AC 100 ms
75,812 KB
testcase_08 AC 98 ms
75,944 KB
testcase_09 AC 94 ms
75,944 KB
testcase_10 AC 90 ms
75,964 KB
testcase_11 AC 158 ms
77,996 KB
testcase_12 AC 137 ms
77,376 KB
testcase_13 AC 143 ms
78,020 KB
testcase_14 AC 142 ms
78,004 KB
testcase_15 AC 134 ms
77,344 KB
testcase_16 AC 146 ms
77,768 KB
testcase_17 AC 110 ms
76,356 KB
testcase_18 AC 150 ms
77,576 KB
testcase_19 AC 155 ms
83,276 KB
testcase_20 AC 151 ms
83,260 KB
testcase_21 AC 159 ms
83,492 KB
testcase_22 AC 515 ms
98,836 KB
testcase_23 AC 550 ms
97,716 KB
testcase_24 AC 589 ms
97,808 KB
testcase_25 AC 592 ms
98,452 KB
testcase_26 AC 581 ms
98,200 KB
testcase_27 AC 584 ms
97,432 KB
testcase_28 AC 477 ms
97,184 KB
testcase_29 AC 204 ms
98,952 KB
testcase_30 AC 241 ms
96,924 KB
testcase_31 AC 524 ms
96,420 KB
testcase_32 AC 446 ms
98,176 KB
testcase_33 AC 141 ms
83,264 KB
testcase_34 AC 410 ms
97,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin, setrecursionlimit
from collections import deque
import bisect
input = stdin.readline
readline = stdin.readline
N,M=map(int, input().split())
kousa=[]
syoko=[]
for i in range(N):
  s,k=map(int,input().split())
  kousa.append(k)
  syoko.append(s)

def SuMD(i:int,p:int):
  if p==0:
    return 0
  return syoko[i]*p+p*(p-1)//2*kousa[i]

def f_i(i:int,x:int):
  if x<=syoko[i]:
    p=0
  elif x>syoko[i]+kousa[i]*(M-1):
    p=M
  else:
    p=(x-syoko[i]-1)//kousa[i]+1
  return (SuMD(i,M)-2*SuMD(i,p))+(2*p-M)*x

def CH(i:int,j:int,k:int)->bool:
  L,R=0,10**9+1
  while R-L>1:
    mid=(L+R)//2
    if f_i(j,mid)<=f_i(k,mid):
      L=mid
    else:
      R=mid
  if f_i(i,R-1)<=f_i(j,R-1):
    return True
  else:
    return False

d=deque()
dlen=0
for i in range(N):
  while dlen>=2 and CH(d[-2],d[-1],i):
    d.pop()
    dlen-=1
  d.append(i)
  dlen+=1


Q,X=map(int,input().split())
A=list(map(int, input().split()))

AN=[0]*Q
for q in range(Q):
  while dlen>=2 and f_i(d[0],X)>f_i(d[1],X):
    dlen-=1
    d.popleft()
  AN[q]=d[0]+1
  X+=A[AN[q]-1]
  if X>10**9+5:
    X=10**9+5

print(*AN)
0