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.

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 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 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 <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
struct Node
{
int x,y;
}a[N];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int sl=,sr=;
for(int i=;i<n;i++){
cin>>a[i].x>>a[i].y;
sl+=a[i].x;
sr+=a[i].y;
}
int s=abs(sl-sr);
int d=,t=;
for(int i=;i<n;i++){
if(s<abs((sl-a[i].x+a[i].y)-(sr-a[i].y+a[i].x))){
s=abs((sl-a[i].x+a[i].y)-(sr-a[i].y+a[i].x));
t=i+;
}
}
cout<<t<<endl;
return ;
}

Codeforce 733B - Parade (枚举)的更多相关文章

  1. CodeForces 733B Parade

    B. Parade time limit per test1 second memory limit per test256 megabytes inputstandard input outputs ...

  2. 【非常高%】【codeforces 733B】Parade

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. codeforce Pashmak and Buses(dfs枚举)

    /* 题意:n个同学,k个车, 取旅游d天! 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 也就 ...

  4. codeforce No to Palindromes!(枚举)

    /* 题意:给定一个字符串中没有任何长度>1的回文子串!求按照字典序的该串的下一个字符串 也不包含长度>1的任何回文子串! 思路:从最低位进行枚举,保证第i位 不与 第 i-1位和第 i- ...

  5. codeforce 589B枚举

    2017-08-25 12:00:53 writer:pprp 很简单的枚举,但是我调试了很长时间,出现各种各样的问题 /* theme:cf 589B writer:pprp declare:枚举 ...

  6. Rain on your Parade

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  7. Parade

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

  8. Parade(单调队列优化dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2490 Parade Time Limit: 4000/2000 MS (Java/Others)    ...

  9. HDU 2389 ——Rain on your Parade——————【Hopcroft-Karp求最大匹配、sqrt(n)*e复杂度】

    Rain on your Parade Time Limit:3000MS     Memory Limit:165535KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. dedecms怎样调用指定id文章?

    前面我们聊了帝国cms如何调用指定id的文章到首页,作为同行的织梦cms应该也是可以实现的吧?那么,dedecms怎样调用指定id文章呢?使用idlist直接调用指定的ID这样的方法是比较好的.官方给 ...

  2. 20180322 对DataTable里面的数据进行去重

    对DataTable里面的数据进行去重 DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt. ...

  3. MACD:黄白线、红绿柱与0轴关系

    一.MACD的基本问题: (1)参数:统一用12,26,9 (2)MACD   位正.位不正原则 以下四种情况是黄白线.红绿柱与0轴关系的完全分类,行情出不了这四种情况, 即便黄白线在0轴单边反复缠绕 ...

  4. windows系统redmine安装总结

    今天在公司服务器上安装了redmine,主要用于项目管理和缺陷跟踪.安装过程比较简单,总结如下: 1.网上下载redmine安装包(bitnami-redmine-3.3.1-0-windows-in ...

  5. 【分类器】感知机+线性回归+逻辑斯蒂回归+softmax回归

    一.感知机     详细参考:https://blog.csdn.net/wodeai1235/article/details/54755735 1.模型和图像: 2.数学定义推导和优化: 3.流程 ...

  6. 对Python源码加密及反编译前后对比

    关于python的加密 目前软件开发商对 Python 加密时可能会有两种形式,一种是对python转成的exe进行 保护,另一种是直接对.py或者.pyc文件进行保护,下面将列举两种形式的保护流程. ...

  7. [py]类的专有方法

    陆陆续续总结一些用到的类的特殊方法 看源码总会看到一些奇奇怪怪的写法: 掺杂着设计模式 https://coding.net/u/RuoYun/p/Python-design-pattern/git/ ...

  8. 查看npm仓库版本号

    http://repo.inspur.com:8081/artifactory/webapp/#/artifacts/browse/simple/General/thirdparty iop 找到现在 ...

  9. react 全局公共组件-----动态弹窗 (dialog)

    react 的时候,总是会用到弹窗,并且各种各样的,一般来说,组件层级嵌套之后,就会出现 z-index层级覆盖的问题 这个时候,就需要一个公共的弹出层,然后我们将需要展示的组件,放到弹出层里面 下面 ...

  10. python入门之列表

    1.列表基本格式# list 类 列表li = [1, 2, 3, "sb", ["时间",[9, 10], "huang"], 6, 7, ...