You are given a Young diagram.
Given diagram is a histogram with n columns of lengths a1,a2,…,an (a1≥a2≥…≥an≥1).
Young diagram for a=[3,2,2,2,1].
Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1×2 or 2×1 rectangle.
Input
The first line of input contain one integer n (1≤n≤300000): the number of columns in the given histogram.
The next line of input contains n integers a1,a2,…,an (1≤ai≤300000,ai≥ai+1): the lengths of columns.
Output
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
Example
inputCopy
5
3 2 2 2 1
outputCopy
4
Note
Some of the possible solutions for the example:
解析:基于涂色用黑白两色给图上色,相邻方格不同色。数量少的颜色一定可匹配完。取两者最小值
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1000;
typedef long long ll;
int c[N],n;
ll b[N];
int main()
{
cin>>n;
for(ll i=0;i<n;i++)
{
cin>>c[i];
b[i%2]+=c[i]/2+c[i]%2;
b[(i+1)%2]+=c[i]/2;
}
cout<<min(b[0],b[1])<<endl;
}