https://www.codechef.com/TNP52021/problems/TNP501

#PROBLEM LINK:
https://www.codechef.com/TNP52021/problems/TNP501

Practice

Author: Setter’s Name

Tester: Tester’s Name

Editorialist:Editorialist’s name

DIFFICULTY : BEGINNER

#PREREQUESITES:

NILL

#PROBLEM:

David is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he’s not sure which movie he should watch.
There are n movies to watch during this weekend. Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. David wants to watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, he would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with the minimal index among them.
Your task is to help David to pick a movie to watch during this weekend.

SOLUTIONS:

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 101;

int l[MAX_N];
int r[MAX_N];

void solve() {
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> l[i];
}
for (int i = 0; i < n; i++) {
cin >> r[i];
}

int answer = 0;
for (int i = 1; i < n; i++) {
if (make_pair(l[answer] * r[answer], r[answer]) < make_pair(l[i] * r[i], r[i])) {
answer = i;
}
}

cout << answer + 1 << “\n”;
}

int main() {
int cases; cin >> cases;

for (int i = 0; i < cases; i++) {
solve();
}

return 0;
}