Little Jay

[C++] 백준 2839번 - 설탕 배달 본문

알고리즘/BOJ

[C++] 백준 2839번 - 설탕 배달

Jay, Lee 2021. 8. 4. 14:34

greedy하게 풀었다

이게 greedy하게 푸는 방법이라 내가 쓴 코드가 정답이 아닐 수도 있다

다른 블로그들 참고하니까 dq로 푸는 방법도 있는 것 같은데

아직은 dq를 모르므로 pass

 

#include <iostream>
#include <vector>
using namespace std;

int main() {

	int n;
	cin >> n;

	int bags = 0;

	while (n >= 0) {
		if (n % 5 == 0) {	
			bags += (n / 5);
			cout << bags << endl;

			return 0;
		}
		n -= 3;
		bags++;
	}
	cout << -1 << endl;

	return 0;
}
Comments