/*
https://www.acmicpc.net/problem/2839
The idea is, we have to use 5KG bag as mush as possible.
so start with the maximum number of 5KG bags, repeat checking and reducing the number of 5KG bags.
*/
#include <iostream>
using namespace std;
int main(){
int n;
int kg5=0,kg3=0;
int rem=0,answer=0;
cin >> n;
if((n<3)||(n>5000)){
answer = -1;
cout << answer;
return 0;
}
if(n%5 == 0){ //If n is a multiple of 5, get the answer quickly
answer = n/5;
cout << answer;
return 0;
}
for(kg5 = n/5; kg5 >=0; kg5--){
rem = n - (kg5*5); //exclude an amount of 5kg sugar
if(rem%3 == 0){ //check its remainder is 0
kg3 = rem/3;
break; //we got the answer. go out.
}
//reduce kg5 and repeat.
}
//If this loop couldn't get the answer, then kg5 must be -1, kg3 must be 0. In the case, kg5 + kg3 is -1.
answer = kg5 + kg3;
cout << answer;
return 0;
}
댓글 없음:
댓글 쓰기