8000 Merge pull request #422 from haneulkimdev/patch-2 · dostiny/basic-algo-lecture@f07afc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f07afc0

Browse files
Merge pull request encrypted-def#422 from haneulkimdev/patch-2
Update 2839.cpp
2 parents 45b7d31 + 24df7f0 commit f07afc0

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

0x12/solutions/2839.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : haneulkimdev
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/3649d2bc821d41be958cb51fc82946d3
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
int main(void) {
88
ios::sync_with_stdio(0);
99
cin.tie(0);
10-
11-
}
10+
int n;
11+
cin >> n;
12+
int ans = 0;
13+
while (n >= 0) {
14+
if (n % 5 == 0) {
15+
ans += n / 5;
16+
cout << ans;
17+
return 0;
18+
}
19+
n -= 3;
20+
ans++;
21+
}
22+
cout << -1;
23+
}
24+
25+
/*
26+
3킬로그램 5개는 5킬로그램 3개로 치환이 되기 때문에 3킬로그램은 4개 이하로 사용하면 된다.
27+
n이 5의 배수가 될 때 까지 3으로 빼주면 되는데, 이 때 n이 음수가 된다면
28+
정확하게 n킬로그램을 만들 수 없는 상황이다.
29+
*/

0 commit comments

Comments
 (0)
0