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

5432번 - Stifling the Mutiny 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB46161433.333%

문제

A group of pirates is travelling in a convoy of ships, sailing in a row. However, the pirate captain is starting to lose control, and some disloyal pirates are ready to mute. As soon as on any ship S, the number of loyal pirates on S is outnumbered by the combined number of disloyal pirates on S, the previous ship (if S is not the first), and the next ship (if S is not the last) in the convoy, the disloyal pirates on these ships will row to S and take it over. To prevent an outbreak of mutiny, the captain decides to distribute the loyal and disloyal pirates over the ships in such a way that the disloyal pirates cannot capture any ship. Of course, each ship must have at least one loyal pirate to operate the ship.

입력

The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:

  • One line with two integers n and k, where 1 ≤ n ≤ 15 and n ≤ k ≤ 40. The first number is the number of ships; the second number is the total number of pirates (whether loyal or disloyal) in the convoy.

출력

For every test case in the input, the output should contain one integer on a single line: the maximum number of disloyal pirates that the captain can distribute over the ships such that the disloyal pirates cannot capture any ship.

제한

예제 입력 1

3
1 3
3 4
3 16

예제 출력 1

1
1
5

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2011 Preliminaries A번

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

출처

대학교 대회

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

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