Skip to content

Instantly share code, notes, and snippets.

@lifez
Created March 31, 2013 14:37
Show Gist options
  • Select an option

  • Save lifez/5280802 to your computer and use it in GitHub Desktop.

Select an option

Save lifez/5280802 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
int limit,a,b,ans,j,i,four,temp;
int x[100], d[100];
scanf("%d",&limit);
for (a=0;a<limit;a++){
scanf("%d",&x[a]);
}
for(a=0;a<limit;a++){
for(b=0;b<limit-a;b++){
if(x[b]<x[b+1]){
temp=x[b+1];
x[b+1]=x[b];
x[b]=temp;
}
}
}
ans = 0;
j = limit-1;
i = 0;
while (i<=j){
ans+=1;
four = 4-x[j];
while(x[j]<=four && j>=i){
four =four - x[j];
j--;
}
i++;
}
printf("%d",ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment