승쨩개발공부
[BJ] 2839 - 설탕배달 (그리디) 본문
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int n;
int ret = -1;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = n / 5; i >= 0; --i) // 5로나눈 최대값
{
int rest = n - (5 * i); // 5로 나눈 나머지
if (rest % 3 == 0) // 3으로 나누어질떄
{
ret = i + (rest / 3);
break;
}
}
cout << ret;
return 0;
}'CodingTestTraining > BaekJoon(Basic)' 카테고리의 다른 글
| [BJ] 6603 - 로또 (백트래킹) (0) | 2025.10.28 |
|---|---|
| [BJ] 1697 - 숨바꼭질 (BPS 1차원 최단거리 변형) (0) | 2025.10.28 |
| [BJ] 1260 - DFS와 BFS (그래프) (0) | 2025.10.28 |
| [BJ] 2568 - 안전 영역 (DFS 모든 경우의 수) (0) | 2025.10.28 |
| [BJ] 1629 - 곱샘 (재귀기초, 모듈러 성질, 귀납적사고) (0) | 2025.03.06 |