D.Domino for Young
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
Input
5
3 2 2 2 1
Output
4
Note
Some of the possible solutions for the example:
题意:
见题目样例和题目图片
问最多能摆放多少个1*2的多米诺骨牌
思路:
交叉染色:
3,2,2,2,1
染色之后就是
1
0 1 0 1
1 0 1 0 1
其中1有6个,0有4个
每一张多米诺骨牌,无论如何摆放,一定消耗一个1和一个0
所以答案就是min(1的个数,0的个数)
ps:
不知道为啥感觉这操作在哪见过
code:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int cnt[2];
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
cnt[i%2]+=x/2+x%2;
cnt[(i+1)%2]+=x/2;
}
cout<<min(cnt[0],cnt[1])<<endl;
return 0;
}