fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n, m;
  5. cin >> n>> m;
  6. int card[100];
  7. for (int i = 0; i < n; i++)
  8. cin >> card[i];
  9. int sum = 0;
  10. int temp = 0;
  11. int result = 0;
  12. for (int i = 0; i < n - 2; i++) {
  13. for (int j = 1; j < n - 1; j++) {
  14. for (int k = 2; k < n; k++) {
  15. sum = card[i] + card[j] + card[k];
  16. if (sum <= m) {
  17. temp = sum;
  18. if (temp > result)
  19. result = temp;
  20. }
  21. }
  22. }
  23. }
  24. cout << result;
  25. }
Success #stdin #stdout 0s 4408KB
stdin
5 9
1 1 3 1 1
stdout
9