733B - Parade - CodeForces Solution


math *1100

Please click on ads to support us..

Python Code:

n_cols = int(input())
cols = []
l_tot = 0
r_tot = 0

for i in range(n_cols):
    l_r = input()
    l, r = l_r.split(" ")
    l = int(l)
    r = int(r)
    l_tot += l
    r_tot += r
    cols.append([l, r])

bel_in = abs(l_tot - r_tot)
max_bel = bel_in
max_k = 0

for k in range(len(cols)):
    l_tot_k, r_tot_k = l_tot, r_tot
    l_tot_k += (cols[k][1] - cols[k][0])
    r_tot_k += (cols[k][0] - cols[k][1])
    if abs(l_tot_k - r_tot_k) > max_bel:
        max_bel = abs(l_tot_k - r_tot_k)
        max_k = k + 1
    
print(max_k)

				  	     	 		  			  			   		

C++ Code:

/*
Problem: 733B
Date: 02-10-2023 08:39 PM
*/


#include <bits/stdc++.h>

#define in std::cin
#define out std::cout
#define endl std::endl
#define Max(a, b) std::max(a, b)
#define Max3(a, b, c) std::max(a, std::max(b, c))
#define Min(a, b) std::min(a, b)
#define Min3(a, b, c) std::min(a, std::min(b, c))
#define MaxE(a, b) a = std::max(a, b)
#define MinE(a, b) a = std::min(a, b)
#define Getbit(a, n) ((a >> n) & 1)
#define Bitcount(a) __builtin_popcount(a)
#define Gcd(a) __gcd(a)
#define S std::string
#define Ss std::stringstream
#define VI std::vector<int>
#define VS std::vector<std::string>
#define VPII std::vector<std::pair<int, int> >
#define VPSI std::vector<std::pair<std::string, int> >
#define VPIS std::vector<std::pair<int, std:;string> >
#define VPSS std::vector<std::pair<std::string, std::string> >
#define Mp(a, b) std::make_pair(a, b)
#define PII std::pair<int, int>
#define PSI std::pair<std::string, int>
#define PIS std::pair<int, std::string>
#define PSS std::pair<std::string, std::string>
#define SI std::set<int>
#define SS std::set<std::string>
#define SPII std::set<std::pair<int, int> >
#define SPSI std::set<std::pair<std::string, int> >
#define SPIS std::set<std::pair<int, std::string> >
#define SPSS std::set<std::pair<std::string, std::string> >
#define VII std::vector<int>::iterator
#define VSI std::vector<std::string>::iterator
#define VPIII std::vector<std::pair<int, int> >::iterator
#define VPISI std::vector<std::pair<int, std::string> >::iterator
#define VPSII std::vector<std::pair<std::string, int> >::iterator
#define VPSSI std::vector<std::pair<std::string, std::string> >::iterator
#define MsI std::multiset<int>
#define MsS std::multiset<std::string>
#define SII std::set<int>::iterator
#define SPIII std::set<std::pair<int, int> >::iterator
#define SPSII std::set<std::pair<std::string, int> >::iterator
#define SPISI std::set<std::pair<int, std::string> >::iterator
#define SPSSI std::set<std::pair<std::string, std::string> >::iterator
#define MsII std::multiset<int>::iterator
#define MsSI std::multiset<std::string>::iterator
#define MapII std::map<int, int>
#define MapSS std::map<std::string, std::string>
#define MapIS std::map<int, std::string>
#define MapSI std::map<std::string, int>

int n, l, r;
int amt[100000];
int tot;
int max, maxdex;

int main() {
	in >> n;
	for(int i = 0; i < n; i++) {
		in >> l >> r;
		amt[i] = r - l;
		tot += amt[i];
	}
	max = abs(tot);
	for(int i = 0; i < n; i++) {
		if(abs(tot - 2 * amt[i]) > max) {
			max = abs(tot - 2 * amt[i]);
			maxdex = i + 1;
		}
	}
	out << maxdex;
}


Comments

Submit
0 Comments
More Questions

1080A - Petya and Origami
1642D - Repetitions Decoding
1440A - Buy the String
1658F - Juju and Binary String
478A - Initial Bet
981A - Antipalindrome
365A - Good Number
1204B - Mislove Has Lost an Array
1409D - Decrease the Sum of Digits
1476E - Pattern Matching
1107A - Digits Sequence Dividing
1348A - Phoenix and Balance
1343B - Balanced Array
1186A - Vus the Cossack and a Contest
1494A - ABC String
1606A - AB Balance
1658C - Shinju and the Lost Permutation
1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins