A
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
41 1 2 1
1
22 2
0
72 2 2 1 1 1 1
3
31 1 1
1
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
【题解】
水题
123
int main(){ int n; int x; scanf("%d",&n); int a=0,b=0; for(int i=1;i<=n;i++) { scanf("%d",&x); if(x==1) a++; else b++; } if(a>=b) { cout<B:
int a[13]={31,28,31,30,31,30,31,31,30,31,30,31};int b[50]; int n;int judge(int x,int y)//x-b y-a{ int cot=0; for(int i=y,j=x;jC:1) return 0; } if(a[i%12]!=b[j]) { if(b[j]==29&&a[i%12]==28) continue; return 0; } } return 1;}int main(){ int flag=0; scanf("%d",&n); mem(b,0); for(int i=0;i
int a[MAXN];int main(){ int sum=0; int n; scanf("%d",&n); if(n%2==0) { if(n%4==0) { cout<<0<