Parade。。。。

来源:互联网 发布:兰蔻小黑瓶眼膜霜 知乎 编辑:程序博客网 时间:2024/05/16 20:25

好久好久之前的比赛题一直没补。。。。。。。。每次看到一堆英文就头大。努力看了半天才明白他什么意思。。。。。还因为一些细节WA了好多遍。。。。。

Description

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 iand 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

Standard input will contain multiple test cases. 

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 the min of them.

Sample Input

35 68 910 3

Sample Output

3


就是求输入的每行中哪两个交换之后相减的绝对值最大。然后输出列数。直接暴力。(可怜我WA那么多次)

#include<cstdio>#include<cstring>#include<cmath>using namespace std;int a[100005],b[100005];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int a1=0,a2=0;        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        for(int i=1; i<=n; i++)        {            scanf("%d %d",&a[i],&b[i]);            a1+=a[i];            a2+=b[i];        }        int ans=abs(a1-a2),l=0;        for(int i=1; i<=n; i++)        {            if(ans<abs((a1-a[i]+b[i])-(a2-b[i]+a[i])))            {                ans=abs((a1-a[i]+b[i])-(a2-b[i]+a[i]));                l=i;            }        }        printf("%d\n",l);    }}


0 0
原创粉丝点击