303799: CF733B. Parade
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
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 $ l_{i} $ soldiers, who start to march from left leg, and $ r_{i} $ 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 $ l_{i} $ and $ r_{i} $ . 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.输入输出格式
输入格式
The first line contains single integer $ n $ ( $ 1<=n<=10^{5} $ ) — the number of columns. The next $ n $ lines contain the pairs of integers $ l_{i} $ and $ r_{i} $ ( $ 1<=l_{i},r_{i}<=500 $ ) — the number of soldiers in the $ i $ -th column which start to march from the left or the right leg respectively.
输出格式
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.
输入输出样例
输入样例 #1
3
5 6
8 9
10 3
输出样例 #1
3
输入样例 #2
2
6 5
5 6
输出样例 #2
1
输入样例 #3
6
5 9
1 3
4 8
4 5
23 54
12 32
输出样例 #3
0