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, thei-th column consists of li soldiers, who start to march from left leg, andri 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, andR 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 tellall 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 indexi and swap values li andri.

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 integersli andri (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, or0 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.

Example
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 equal5 + 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 equal5 + 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.

题意:

给出左右了两个数组,要求调换左右数组同一位置的的数字,使得数组和差点绝对值最大;

且只能调换一次,输出该数字在数组中的位置

思路:

求出初始每个数组的和sum1,sum2,每次调换一个位置寻找最大值,并把该位置记录

假设a为num1的数字,b为num2同一位置的数字,现在调换a,b

sum1= sum1-a+b;  sum2=sum2-b+a;

|  sum1 - sum2  |  =  |  (sum1 - sum2 - 2*a + 2*b)  |    (| a |  为a 的绝对值)

代码:

#include<stdio.h>
#define MAX 100005
int num1[MAX],num2[MAX];//存放左右数字
int fab(int a){//求绝对值
    if(a<0) a=-a;
    return a;
}
int main(){
    int n;
    scanf("%d",&n);
    int i;
    int sum1=0,sum2=0;
    for(i=1;i<=n;i++){
        scanf("%d%d",&num1[i],&num2[i]);
        sum1+=num1[i];
        sum2+=num2[i];
    }
    int maxx=fab(sum1-sum2);
    int besti=0;
    for(i=1;i<=n;i++){
       int a,b;
        a=num1[i];
        b=num2[i];
       if(maxx<fab(sum1-sum2-2*a+2*b)){
          besti=i;
          maxx=fab(sum1-sum2-2*a+2*b);
       }
    }
    printf("%d\n",besti);
return 0;
}


### 自动生成 Parade 相关代码或配置 为了在 IntelliJ IDEA 中自动创建 `@Parade` 注解或者相关配置,可以考虑以下几个方面: 对于注解的自动生成,在 Java 开发环境中通常依赖于 IDE 的插件支持或者是通过特定框架提供的功能来实现。如果希望为项目添加一个新的注解 `@Parade` 并让其能够被识别以及触发某些行为,则可能涉及到定义该注解本身及其处理器。 当提到自动化生成与某个特定标签关联的文件时,这往往意味着要利用构建工具或是开发环境所提供的模板机制。例如,在 Maven 或 Gradle 构建脚本里指定资源过滤规则;而在编辑器端则可以通过 Live Templates 功能快速输入重复性的代码片段[^1]。 另外一种方式就是借助 Lombok 这样的库简化样板代码编写工作,不过需要注意的是这里讨论的对象是 `@Parade` 而不是常见的 Lombok 提供的那种类型的注解。因此,除非已经存在类似的第三方库实现了这一需求,否则还是得自己动手完成这部分工作的大部分内容。 针对 IntelliJ IDEA 特有的特性来说,除了上述方法外还可以探索如下选项: - **Live Templates**: 创建自定义 live template 来加速常用模式下 `@Parade` 使用场景中的编码效率。 - **Inspections and Quick Fixes**: 如果有频繁修改的需求,那么设置 Inspection 和对应的 Quick Fix 可能会有所帮助。 - **File/Code Templates**: 修改全局范围内的 File Template 或者 Code Snippet 以便每次新建类的时候都能方便地引入所需的注解声明。 最后值得注意的一点是在实际操作之前应当确认所使用的版本是否兼容这些特性和扩展,并查阅官方文档获取最新指导说明。 ```java // 自定义注解示例 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Parade { String value() default ""; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值