BOJ 2798 블랙잭

1 개요[ | ]

BOJ 2798 블랙잭


2 C++[ | ]

#include <iostream>
using namespace std;

int blackjack(int n, int m, int* card) {
    int maxSum = 0;
    int i, j, k, sum;
    for(i=0; i<n; i++) {
        for(j=i+1; j<n; j++) {
            for(k=j+1; k<n; k++) {
                sum = card[i] + card[j] + card[k];
                if(sum > m) continue;
                if(sum > maxSum) maxSum = sum;
            }
        }
    }
    return maxSum;
}

int main() {
    int N, M;
    cin >> N >> M;
    int card[100] = {0};
    for(int i=0; i<N; i++) {
        cin >> card[i];
    }
    cout << blackjack(N, M, card) << '\n';
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}