Logo
(追記) (追記ここまで)

23642번 - Modular Knapsack 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 (추가 시간 없음) 256 MB95562.500%

문제

Today you should solve unusual knapsack problem. You are given $n$ items, $i$-th of them has weight $w_i$ and cost $c_i$. Also a prime $p$ is given. For every remainder $r$ modulo $p$ you should find the maximum total cost of a set of items with total weight having remainder $r$ modulo $p$. All weights and costs in each test except samples are chosen randomly and independently from range $[0 \dots 10^9]$. $n$ and $p$ are chosen manually.

입력

The first line contains two integers $n,ドル $p$ (1ドル\leq n\leq 10^6, 2\leq p\leq 3000$) -- the number of items and the prime modulo.

The next line contains $n$ integers $w_i$ (0ドル\leq w_i\leq 10^9$) --- the weights of items.

The next line contains $n$ integers $c_i$ (0ドル\leq c_i\leq 10^9$) --- the costs of items.

출력

Output one line with $p$ integers. $i$-th of them (0ドル$-indexed) should be equal to the maximum total cost of a set of items with total weight having remainder $i$ modulo $p,ドル or $-1$ if such set doesn't exist.

제한

예제 입력 1

2 2
1 2
1 1

예제 출력 1

1 2

예제 입력 2

2 2
2 2
1 1

예제 출력 2

2 -1

힌트

출처

Contest > Open Cup > 2018/2019 Season > Stage 8: Grand Prix of Dolgoprudny D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /