Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1edcaae

Browse files
Create Cake 123 Explanation.txt
1 parent ac7d092 commit 1edcaae

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Let us sort A, B and C in non-decreasing order.
2+
3+
A : A_1 >= A_2 >= ... >= A_x
4+
B : B_1 >= B_2 >= ... >= B_y
5+
C : C_1 >= C_2 >= ... >= C_z
6+
7+
The optimum pairing will not have any (i, j, k) such that i*j*k > K.
8+
9+
We need to search at most till i*j*k where i*j*k <= K.
10+
11+
---
12+
13+
int main()
14+
{
15+
int no_of_1_candles, no_of_2_candles, no_of_3_candles, no_of_chosen_cakes;
16+
cin >> no_of_1_candles >> no_of_2_candles >> no_of_3_candles >> no_of_chosen_cakes;
17+
18+
vector <LL> cake_1(no_of_1_candles + 1, 0);
19+
read_and_sort(cake_1, no_of_1_candles);
20+
21+
vector <LL> cake_2(no_of_2_candles + 1, 0);
22+
read_and_sort(cake_2, no_of_2_candles);
23+
24+
vector <LL> cake_3(no_of_3_candles + 1, 0);
25+
read_and_sort(cake_3, no_of_3_candles);
26+
27+
vector <LL> chosen_cakes;
28+
for(int i = 1; i <= no_of_1_candles; i++)
29+
{
30+
for(int j = 1; j <= no_of_2_candles; j++)
31+
{
32+
for(int k = 1; k <= no_of_3_candles; k++)
33+
{
34+
if(i*j*k > no_of_chosen_cakes)
35+
break;
36+
37+
chosen_cakes.push_back(cake_1[i] + cake_2[j] + cake_3[k]);
38+
}
39+
}
40+
}
41+
42+
sort(all(chosen_cakes), greater <LL>());
43+
44+
for(int i = 0; i < no_of_chosen_cakes; i++)
45+
cout << chosen_cakes[i] << "\n";
46+
47+
return 0;
48+
}

0 commit comments

Comments
(0)

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