Skip to content

Commit 4ad4cb0

Browse files
Create Greedy-PP3.c
1 parent be10c11 commit 4ad4cb0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Greedy-Algorithms/Greedy-PP3.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,bill,five=0,ten=0,twenty=0;
5+
scanf("%d",&n);
6+
for(int i=0;i<n;i++)
7+
{
8+
scanf("%d",&bill);
9+
if(bill==5)
10+
five++;
11+
else if(bill==10)
12+
{
13+
if(five>0)
14+
{
15+
five--;
16+
ten++;
17+
}
18+
else
19+
{
20+
printf("false");
21+
return 0;
22+
}
23+
}
24+
else
25+
{
26+
if(ten>0 && five>0)
27+
{
28+
five--;
29+
ten--;
30+
twenty++;
31+
}
32+
else
33+
{
34+
printf("false");
35+
return 0;
36+
}
37+
}
38+
}
39+
printf("true");
40+
}

0 commit comments

Comments
 (0)