https://www.acmicpc.net/problem/2798
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
vector<int> arr;
int max_num = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
arr.push_back(temp);
}
for (int i = 0; i < arr.size() - 2; i++) {
for (int j = i + 1; j < arr.size() - 1; j++) {
for (int q = j + 1; q < arr.size(); q++) {
int temp = arr[i] + arr[j] + arr[q];
if (temp <= m && max_num < temp) {
max_num = temp;
}
}
}
}
cout << max_num;
return 0;
}
'algorithm > Brute force' 카테고리의 다른 글
[백준/7568] 덩치 (0) | 2020.03.31 |
---|---|
[백준/2231] 분해합 (0) | 2020.03.31 |
댓글