結果

問題 No.3397 Max Weighted Floor of Linear
コンテスト
ユーザー amentorimaru
提出日時 2025-12-03 00:34:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,027 ms / 2,000 ms
コード長 710 bytes
記録
コンパイル時間 156 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 87,040 KB
最終ジャッジ日時 2025-12-03 23:39:21
合計ジャッジ時間 18,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
import math


def calc(x,m,a,b,c,d):
  return a*x+(c*x+d)//m*b
def dfs(n,m,a,b,c,d):
  if n==0 or m==0:
    return -10**100
  add=d//m*b
  a+=c//m*b
  c%=m
  d%=m
  tmp=max(calc(0,m,a,b,c,d),calc(n-1,m,a,b,c,d))
  p=(c*(n-1)+d)//m
  if a >= 0:
    return max(tmp,dfs(p,c,b,a,m,m-d-1))+add
  else:
    return max(tmp,dfs(p,c,b,a,m,m-d-1)+a+b)+add
  
def main():
  n,m,a,b,c,d=read_values()
  print(dfs(n,m,a,b,c,d))
  return

if __name__ == "__main__":
  t=int(input())
  for _ in range(t):
    main()

    

0