codeforces 733B - Parade

Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.

The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.

No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri.

Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

Input
The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.

The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

Output
Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.

Consider that columns are numbered from 1 to n in the order they are given in the input data.
 

If there are several answers, print any of them.

 

这是道水题直接暴力枚举就好了,拒绝写解析

 

AC代码:

 

# include <stdio.h>
# include <math.h>
# include <stdlib.h>
using namespace std;
typedef long long int ll;
int  suml[100010], sumr[100010], l[100010], r[100010];
int main(){
	int i, j, k, n, ans, Max, temp;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d%d", &l[i], &r[i]);
	}
	ans=0;suml[0]=0;sumr[0]=0;
	for(i=1; i<=n; i++){
		suml[i]=suml[i-1]+l[i];
		sumr[i]=sumr[i-1]+r[i];
	}
	Max=abs(suml[n]-sumr[n]);
	for(i=1; i<=n; i++){
		if((temp=abs((suml[i-1]+suml[n]-suml[i]+r[i])-(sumr[i-1]+sumr[n]-sumr[i]+l[i])))>Max){
			Max=temp;
			ans=i;
		}
	}
	printf("%d", ans);
	return 0;
} 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值