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

18605번 - Coins 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB112362834.146%

문제

There are n groups of coins, and the i-th group contains two coins valued as ai and bi. Now you want to pick exactly k coins out of them. However, there is a restriction: you can not pick the second coin (the one valued as bi) in the i-th group without picking the other one in the same group. In other words, in the i-th group, you can:

  • pick none of the two coins;
  • pick only the first one valued as ai; or
  • pick both of them.

Let f(k) be the maximum total value if we pick exactly k coins.

Find the values f(1), f(2), . . . , f(2n).

입력

The input contains several test cases, and the first line contains a single integer T (1 ≤ T ≤ 90), the number of test cases.

For each test case, the first line contains an integer n (1 ≤ n ≤ 100 000), indicating the number of coin groups.

Each of the following n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 10 000) indicating the coin values in that group.

It is guaranteed that the sum of n in all test cases does not exceed 2 100 000.

출력

For each test case, just output 2n integers on a single line representing f(1), f(2), . . . , f(2n). Separate consecutive integers by single spaces.

제한

예제 입력 1

2
3
1 2
1 4
4 2
2
1 3
3 2

예제 출력 1

4 6 9 11 12 14
3 5 7 9

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 3: Quailty and His Friends’ Contest H번

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

출처

대학교 대회

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

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