ALGOQ008-Editorial

PROBLEM NAME:

INTERNSHIP

PROBLEM LINK:

(CodeChef: Practical coding for everyone)

DIFFICULTY:

Easy - Medium

PREREQUISITES:

BASIC MATHS

Solution:

We can exhaustively search every pair of indices of employees assigned to Work A and Work B.
The total time complexity of this solution is Θ(N2). Besides, one can also solve this problem in a total of O(N)time.

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::vector<int> a(n);
	std::vector<int> b(n);
	for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri();
	
	int res = 1000000000;
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
		res = std::min(res, i == j ? a[i] + b[j] : std::max(a[i], b[j]));
	printf("%d\n", res);
	
	return 0;
}