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 3592efa

Browse files
Create Cake 123.cpp
1 parent 3a24d5f commit 3592efa

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
#define all(v) (v).begin(), (v).end()
6+
typedef long long LL;
7+
8+
using namespace std;
9+
10+
void read_and_sort(vector <LL> &A, int n)
11+
{
12+
A[0] = 1e15;
13+
14+
for(int i = 1; i <= n; i++)
15+
cin >> A[i];
16+
17+
sort(all(A), greater <LL>());
18+
}
19+
20+
int main()
21+
{
22+
int no_of_1_candles, no_of_2_candles, no_of_3_candles, no_of_chosen_cakes;
23+
cin >> no_of_1_candles >> no_of_2_candles >> no_of_3_candles >> no_of_chosen_cakes;
24+
25+
vector <LL> cake_1(no_of_1_candles + 1, 0);
26+
read_and_sort(cake_1, no_of_1_candles);
27+
28+
vector <LL> cake_2(no_of_2_candles + 1, 0);
29+
read_and_sort(cake_2, no_of_2_candles);
30+
31+
vector <LL> cake_3(no_of_3_candles + 1, 0);
32+
read_and_sort(cake_3, no_of_3_candles);
33+
34+
vector <LL> chosen_cakes;
35+
for(int i = 1; i <= no_of_1_candles; i++)
36+
{
37+
for(int j = 1; j <= no_of_2_candles; j++)
38+
{
39+
for(int k = 1; k <= no_of_3_candles; k++)
40+
{
41+
if(i*j*k > no_of_chosen_cakes)
42+
break;
43+
44+
chosen_cakes.push_back(cake_1[i] + cake_2[j] + cake_3[k]);
45+
}
46+
}
47+
}
48+
49+
sort(all(chosen_cakes), greater <LL>());
50+
51+
for(int i = 0; i < no_of_chosen_cakes; i++)
52+
cout << chosen_cakes[i] << "\n";
53+
54+
return 0;
55+
}

0 commit comments

Comments
(0)

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