Skip to content

Commit

Permalink
설탕 배달
Browse files Browse the repository at this point in the history
  • Loading branch information
yewon-yw authored Apr 11, 2022
1 parent a5c4358 commit 23c8490
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions greedy_algorithm/2839.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
using namespace std;

int main() {
int N, share, mod;
cin >> N;

share = N / 5;
mod = N % 5;
if (mod == 0) {
cout << share << endl;
return 0;
}
while (true) {
if (mod % 3 == 0) {
cout << share + mod / 3 << endl;
return 0;
}
else {
share--;
mod += 5;
}
if (share < 0) {
cout << -1 << endl;
return 0;
}
}
}

0 comments on commit 23c8490

Please sign in to comment.