RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0689

Purchasing Milk

Gold IV 골드 IV
난이도
2s
시간 제한
256MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

On National Milk Day, Farmer John is offering exclusive prices on buckets of
milk! He has \(N\) (\(1 \leq N \leq 10^5\)) deals numbered from \(1\) to \(N\). For the
\(i\)'th deal, he is offering \(2^{i-1}\) buckets of milk for \(a_i\)
(\(1 \leq a_i \leq 10^9, a_i < a_{i+1}\)) moonies. The same deal may be taken any
non-negative integer number of times.

You are thinking about \(Q\) (\(1 \leq Q \leq 10^4\)) independent queries. For each query, you
have an integer \(x\) (\(1 \leq x \leq 10^9\)) in mind and wonder what is the
minimum cost to purchase at least \(x\) buckets of milk.

Problem credits: Chongtian Ma

제약

SCORING

  • Inputs 3-4: \(N \leq 2\)
  • Inputs 5-8: \(N \leq 10\)
  • Inputs 9-16: No additional constraints.

Problem credits: Chongtian Ma

입력 형식

The first line contains two integers \(N\) and \(Q\).

The following line contains \(a_1, a_2, \ldots, a_N\).

Each of the following \(Q\) lines contains an integer \(x\), representing a query.

출력 형식

For each query, output the minimum cost on a new line.

Note that the large size of integers involved in this problem may require the
use of 64-bit integer data types (e.g., a "long long" in C/C++).

예제 1
입력
2 4
10 15
1
2
6
7
출력
10
15
45
55
설명

In the example above, Farmer John is offering 2 deals: 1 bucket of milk for 10
moonies and 2 buckets of milk for 15 moonies.

The cheapest cost to buy 1 bucket is just the cost of the 1 bucket deal and the
cheapest cost to buy 2 buckets is just the cost of the 2 bucket deal.

To get 6 buckets, the cheapest way is to purchase 3 of the 2 bucket deal for a
total of 45 moonies.

To get 7 buckets, the cheapest way is to purchase 3 of the 2 bucket deal and 1
of the 1 bucket deal for a total of 55 moonies.

예제 2
입력
4 10
10 25 30 70
1
2
3
4
5
6
7
8
15
101
출력
10
20
30
30
40
50
60
60
120
760
설명

In this example, Farmer John is offering a total of 4 deals for 1, 2, 4, and 8
buckets. For each of the 10 queries, the corresponding output indicates the
minimum cost to purchase at least that amount of milk. Sometimes, it is cheaper
to purchase more than the specified amount.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Second Contest > Bronze

태그

평가 및 의견

Purchasing Milk

개요
출제자 난이도 Gold IV 골드 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Purchasing Milk

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8