반응형
https://www.acmicpc.net/problem/2798
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int MAX = -987654321;
int N, M;
void Solve(vector<int> v, vector<int> choose, int i) {
choose.push_back(v[i]);
int sum = 0;
for (int s = 0;s < choose.size();s++)
sum += choose[s];
if (sum > M) return;
if (choose.size() == 3) {
MAX = max(MAX, sum);
return;
}
for (int j = i + 1;j < N;j++)
Solve(v, choose, j);
}
int main(void) {
vector <int> v;
int c;
cin >> N >> M;
for (int i = 0;i < N;i++) {
cin >> c;
v.push_back(c);
}
vector <int> choose;
for(int i=0;i<N;i++)
Solve(v, choose, i);
cout << MAX << endl;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형