코딩테스트/그리디|힙
[그리디] 백준 2839 설탕 배달 C++
유(YOO)
2022. 2. 9. 11:54
https://www.acmicpc.net/problem/2839
#include<iostream>
#define INF 1234567891
using namespace std;
int n, ans, a;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
ans = INF;
for (int i = 0; i < n / 5 + 1; i++) {
a = n - 5 * i;
if (a % 3 == 0) ans = min(ans, a / 3 + i);
}
if (ans == INF) ans = -1;
cout << ans;
}