mustak1's blog

By mustak1, history, 5 years ago, In English

include <stdio.h>

int main() { int n,i,sum=0,c4=0,c3=0,c2=0,c1=0; scanf("%d",&n); int s[n]; for(i=0;i<n;i++) { scanf("%d",&s[i]); if(s[i]==4) c4++; else if(s[i]==3) c3++; else if(s[i]==2) c2++; else c1++; } sum=sum+c4; c4=0; sum=sum+(c2/2); c2=c2%2; if(c3 >= c1) { sum=sum+c1; c3=c3-c1; c1=0; sum=sum+c3; c3=0; sum=sum+c2; c2=0; } else if(c1>c3) { sum=sum+c3; c1=c1-c3; c3=0; sum=sum+(c1/4); c1=c1%4; if((c1+c2*2)<=4 && (c1+c2*2)>0) { sum=sum+1; c1=0; c2=0; } else if(c2==1 && c1==3) { sum=sum+2; c1=0; c2=0; } } printf("%d\n",sum); return 0; }

  • Vote: I like it
  • -12
  • Vote: I do not like it