[codeforces] B. Parade 简单暴力

B. Parade
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 risoldiers, 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.

Examples
input
3
5 6
8 9
10 3
output
3
input
2
6 5
5 6
output
1
input
6
5 9
1 3
4 8
4 5
23 54
12 32
output
0
Note

In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.

If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.

It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.



#include <iostream>   
#include <cstdio>  
#include <cstdlib>  
#include <cmath>  
#include <algorithm>  
#include <climits>  
#include <cstring>  
#include <string>  
#include <set>  
#include <map>  
#include <queue>  
#include <stack>  
#include <vector>  
#include <list>  
#define rep(i,m,n) for(i=m;i<=n;i++)  
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)  
const int inf_int = 2e9;  
const long long inf_ll = 2e18;  
#define inf_add 0x3f3f3f3f  
#define mod 1000000007  
#define vi vector<int>  
#define pb push_back  
#define mp make_pair  
#define fi first  
#define se second  
#define pi acos(-1.0)  
#define pii pair<int,int>  
#define Lson L, mid, rt<<1  
#define Rson mid+1, R, rt<<1|1  
const int maxn=5e2+10;  
using namespace std;  
typedef  long long ll;  
typedef  unsigned long long  ull;   
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;  
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')  
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,  
rx=getchar();return ra*fh;}  
//#pragma comment(linker, "/STACK:102400000,102400000")  
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}  
int main()
{
	int n;
	int a[100005],b[100005];
	ll l=0,r=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin >> a[i] >>b[i] ;
		l+= a[i];
		r+= b[i];
	}
	ll maxx = abs(l-r);
	int re = 0;
	for(int i=1;i<=n;i++)
	{
		ll t = 0;
		if((t = abs((l-a[i]+b[i])-(r-b[i]+a[i])))>maxx)
		{
			maxx = t;
			re = i;
		}
	}
	cout << re << endl;
		
	return 0;
} 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值