[BOJ] 2839 설탕 배달

Time Lapse :NONE

2839.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
int main(void)
{
int kg;
int kg_5=0;
int kg_3=0;
scanf("%d",&kg);
while(kg_5*5<kg)
{
kg_5++;
}
if((kg_5*5)==kg)
{
printf("%d\n",kg_5);
}
else
{
while((kg_5*5+kg_3*3)!=kg)
{
kg_5--;
kg_3=0;
if(kg_5<0)
kg_5=0;
//kg_3++;
while((kg_5*5+kg_3*3)!=kg)
{
kg_3++;
if((kg_5*5+kg_3*3)>kg)
break;
}
if((kg_5*5+kg_3*3)==kg)
{

printf("%d\n",kg_5+kg_3);
return 0;
}
if(kg_3*3>kg)
{
printf("-1\n");
return 0;
break;
}
}
printf("%d\n",kg_5+kg_3);
}

return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2839/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.