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

25097번 - Controlled Inflation 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB119857075.269%

문제

The lines at the air pump at your gas station are getting too long! You want to optimize the process to help customers more quickly inflate their tires, sports balls, giant parade balloon animals, and other products.

The pump is automatic: you set the pressure to a specific number of pascals and plug the pump into the inflatable product, and it will inflate as needed to that exact pressure. There are only two buttons on the pump: up and down. They increase and decrease the target pressure, respectively, by exactly 1ドル$ pascal.

There is a line of $N$ customers, each of whom brings exactly $P$ products that they need to get inflated by the pump. You know the target pressure of each product. You can inflate the products from a customer in any order you want, but you cannot change the order of the customers. Specifically, you must inflate all products from the $i$⁠-th customer before inflating any from the $(i+1)$⁠-th customer. In between handling two products, if those two products have different target pressures, you need to use the buttons on the pump.

The pump is initially set to 0ドル$ pascals, and it can be left at any number after all products of all customers have been inflated. If you order the products of each customer optimally, what is the minimum number of button presses you need?

입력

The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case starts with a line containing two integers, $N$ and $P$: the number of customers and the number of products each customer brings, respectively. Then, $N$ lines follow. The $i$-th of these lines contains $P$ integers $X_{i,1},X_{i,2},\dots,X_{i,P},ドル representing that the $j$-th product that the $i$-th customer brings has a target pressure of $X_{i,j}$ pascals.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the minimum number of button presses needed to inflate all products according to their specified pressures.

제한

  • 1ドル≤T≤100$.
  • 1ドル≤X_{i,j}≤10^9,ドル for all $i,j$.

Test Set 1 (14점)

  • 2ドル≤N≤10$.
  • 2ドル≤P≤3$.

Test Set 2 (21점)

  • 2ドル≤N≤1000$.
  • 2ドル≤P≤100$.

예제 입력 1

2
3 3
30 10 40
20 50 60
60 60 50
5 2
1 1000000000
500000000 1000000000
1 1000000000
500000000 1
1 1000000000

예제 출력 1

Case #1: 110
Case #2: 4999999996

힌트

In Sample Case #1, an optimal way to use the pump is:

  1. press up 10ドル$ times, setting the pump to 10ドル$; pump the product (from customer 1) that needs 10ドル$ pascals,
  2. press up 30ドル$ times, setting the pump to 40ドル$; pump the product (from customer 1) that needs 40ドル$ pascals,
  3. press down 10ドル$ times, setting the pump to 30ドル$; pump the product (from customer 1) that needs 30ドル$ pascals,
  4. press down 10ドル$ times, setting the pump to 20ドル$; pump the product (from customer 2) that needs 20ドル$ pascals,
  5. press up 30ドル$ times, setting the pump to 50ドル$; pump the product (from customer 2) that needs 50ドル$ pascals,
  6. press up 10ドル$ times, setting the pump to 60ドル$; pump the product (from customer 2) and the two products (from customer 3) that need 60ドル$ pascals, and finally
  7. press down 10ドル$ times, setting the pump to 50ドル$; pump the product (from customer 3) that needs 50ドル$ pascals.

This is a total of 110ドル$ button presses.

In Sample Case #2, notice that the answer can be larger than 232ドル$.

출처

Contest > Google > Code Jam > Google Code Jam 2022 > Round 1B B번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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