https://www.acmicpc.net/problem/2839
#include <iostream>
#define endl "\n"
using namespace std;
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input;
int box5, box3;
int answer;
int count;
cin >> input;
box5 = input / 5;
while (true) {
count = input - (box5 * 5);
if (count % 3 == 0) {
box3 = count / 3;
cout << box5 + box3;
break;
}
else {
box5--;
}
if (box5 == -1) {
cout << -1;
break;
}
}
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 9012 괄호 (0) | 2024.12.31 |
---|---|
C++ 알고리즘 - 백준 4949 균형잡힌 세상 (0) | 2024.12.31 |
C++ 알고리즘 - 백준 2164 카드2 (0) | 2024.12.30 |
C++ 알고리즘 - 백준 1920 수 찾기 (이진탐색 알고리즘) (0) | 2024.12.30 |
C++ 알고리즘 - 백준 1018 체스판 다시 칠하기 (0) | 2024.12.29 |