結果

問題 No.2453 Seat Allocation
ユーザー chineristACchineristAC
提出日時 2023-09-01 23:43:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,521 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 603,356 KB
最終ジャッジ日時 2025-01-03 12:57:38
合計ジャッジ時間 11,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 1 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random
from itertools import permutations
from collections import deque

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = mi()
A = li()
B = li()

A_val = [a for a in A]
A_val.sort()

def cond(x):
    res = 0
    lower = 0
    for b in B:
        while lower!=N and A_val[lower] < x * b:
            lower += 1
        res += N - lower
    return res >= M

ok = 0
ng = 10**9+1
for _ in range(60):
    mid = (ok+ng)/2
    if cond(mid):
        ok = mid
    else:
        ng = mid

select = []
for i,a in enumerate(A):
    for j in range(M):
        b = B[j]
        if a/b >= ok:
            select.append((i,j))
        else:
            break

def comp(a,b):
    if A[a[0]] * B[b[1]] < A[b[0]] * B[a[1]]:
        return True
    if A[a[0]] * B[b[1]] > A[b[0]] * B[a[1]]:
        return False
    return a[0] > b[0]

def merge_sort(A,B):
    pos_A,pos_B = 0,0
    n,m = len(A),len(B)
    res = []
    while pos_A < n and pos_B < m:
        a,b = A[pos_A],B[pos_B]
        if comp(a,b):
            res.append(a)
            pos_A += 1
        else:
            res.append(b)
            pos_B += 1
    res += A[pos_A:]
    res += B[pos_B:]
    return res

def sort_by_comp(_A):
    A = [a for a in _A]
    if len(A) == 1:
        return A
    
    n = len(A)
    left = sort_by_comp(A[:n//2])
    right = sort_by_comp(A[n//2:])
    return merge_sort(left,right)


select = sort_by_comp(select)[::-1]

for i,j in select[:M]:
    print(i+1)






0