https://www.acmicpc.net/problem/14916
짱 쉬운 그리디 문제다.
5로 나눈 몫을 가지고 이렇게 저렇게 활용하면 된다.
추가로 거스름 돈을 만들 수 없는 경우 -1을 출력하는 것도 잊지 말자.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
int a = n / 5;
for (; a >= 0; a--)
{
int tmp = n - (5 * a);
if (tmp % 2 == 0)
{
cout << a + (tmp / 2);
return 0;
}
}
cout << -1;
}
끗
728x90
'백준이당' 카테고리의 다른 글
[C++] 백준 1541번 : 잃어버린 괄호 (0) | 2025.03.25 |
---|---|
[C++] 백준 1072번 : 게임 (0) | 2025.03.25 |
[C++] 백준 20055번 : 컨베이어 벨트 위의 로봇 (0) | 2025.03.21 |
[C++] 11399번 : ATM (0) | 2024.08.19 |
[python, C++] 백준 9663 : N-queen (0) | 2024.05.16 |