-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2798.cpp
More file actions
33 lines (31 loc) · 704 Bytes
/
2798.cpp
File metadata and controls
33 lines (31 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
vector<int> input(N);
for (int i = 0; i < N; i++)
cin >> input[i];
int sum = 0, max = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (i != j)
{
for (int k = 0; k < N; k++)
{
if (j != k && i != k)
{
sum = input[i] + input[j] + input[k];
if (sum <= M && max < sum)
max = sum;
}
}
}
}
}
cout << max;
}