結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 09:44:23 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 446 ms / 2,000 ms |
| コード長 | 1,374 bytes |
| 記録 | |
| コンパイル時間 | 362 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 119,380 KB |
| 最終ジャッジ日時 | 2026-04-18 09:44:35 |
| 合計ジャッジ時間 | 12,353 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
# snippet: templete_
# Last Modified: 2026-02-13
from collections import deque, defaultdict
from itertools import permutations, product
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop
from random import randint, shuffle
from time import perf_counter as pc
def II(): return int(input())
def LI(): return list(map(int,input().split()))
def LI_1(): return [int(x) - 1 for x in input().split()]
def SI(): return input()
def LS(): return list(input().split())
mod = 998244353
inf = 1001001001001001001
import sys
sys.setrecursionlimit(10 ** 6)
input = lambda: sys.stdin.readline().rstrip()
_buf = []
def print(*a, **k): _buf.append(" ".join(map(str, a)))
# snippet: isqrt_
# Last Modified: 2026-02-12
from math import sqrt
def isqrt(x):
y = int(sqrt(x))
while (y + 1) * (y + 1) <= x:
y += 1
while y * y > x:
y -= 1
return y
def solve():
N, W = LI()
X = LI()
Y = LI()
mx = 2 * 10 ** 5
dp = [0] * (mx + 1)
for i in range(N):
for j in range(1, isqrt(X[i]) + 1):
if X[i] % j == 0:
dp[j] += Y[i]
if X[i] != j * j:
dp[X[i] // j] += Y[i]
ans = max(dp[W:])
print(ans)
return
if __name__ == "__main__":
T = 1
# T = II()
for _ in range(T):
solve()
sys.stdout.write("\n".join(_buf) + "\n")