CodeForces 1269 D.Domino for Young (交叉染色)

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

其中16个,04个
每一张多米诺骨牌,无论如何摆放,一定消耗一个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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值