문제 풀이/문제 풀이(BOJ)

[Silver V] 거스름돈 - 14916

풀뿌리 2024. 8. 12. 10:11

 

[문제 위치]

https://www.acmicpc.net/problem/14916

[문제 풀이]

5원을 최대한 주고 남은 양을 2원으로 줄 수 있는지 판단하면 되는 문제이다.

#include <iostream>
using namespace std;

#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main() {
    fastio;  // 빠른 입출력 설정

    int n;
    cin >> n;

    for (int i = n / 5; i >= 0; i--) {
        int remainder = n - 5 * i;
        if (remainder % 2 == 0) {
            cout << i + (remainder / 2) << '\n';
            return 0;
        }
    }
    
    cout << -1 << '\n';
    return 0;
}