Created
August 22, 2020 06:28
-
-
Save HADMARINE/a68677209992d3c6c496f89d790f4823 to your computer and use it in GitHub Desktop.
백준 2839: 설탕배달
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int return_sum(int three_count, int five_count) { | |
return three_count * 3 + five_count * 5; | |
} | |
int main(void) { | |
int num; | |
std::cin >> num; | |
for(int i = num / 5; i >= 0; i--) { | |
int three_num = 0; | |
while(true){ | |
int sum = return_sum(three_num, i); | |
if(sum < num) { | |
three_num++; | |
continue; | |
} | |
if(sum == num) { | |
std::cout << three_num + i << std::endl; | |
i = -1; | |
break; | |
} | |
if(sum > num){ | |
break; | |
} | |
} | |
if(i == 0) { | |
std::cout << -1 << std::endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment