Lucy at the Film Festival
Lucy at the Film Festival
Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. Lucy wants to watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, she would pick a one with the maximal Ri among them. If there is still a tie, she would pick the one with the minimal index among them.
Write a program to help Lucy pick a movie to watch at the film festival.
Input Format:
The first line of the input description contains an integer n. Assume that the maximum value for n as 50.
The second line of the input description contains n integers L1, L2, ...,Ln.
The following line contains n integers R1, R2, ...,Rn.
Output Format:
Output a single integer i denoting the index of the movie that Lucy should watch in the film festival. Note that you follow 1-based indexing.
Refer sample input and output for formatting specifications.
Sample Input 1:
2
1 2
2 1
Sample Output 1:
1
Sample Input 2:
4
2 1 4 1
2 4 1 4
Sample Output 2:
2
#include<stdio.h> #include<stdlib.h> int main() { int *a,*b; int n,i,max,m,count=0; scanf("%d",&n); a=(int*)malloc(n*sizeof(int)); b=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++){ scanf("%d",a+i); } for(i=0;i<n;i++){ scanf("%d",b+i); }i=0; max=*(a+i)**(b+i); for(i=0;i<n;i++){ if(max<*(a+i)**(b+i)){ max=*(a+i)**(b+i); } } for(i=0;i<n;i++){ if(max==*(a+i)**(b+i)){ count++; } } if(count==1){ for(i=0;i<n;i++){ if(max==*(a+i)**(b+i)){ printf("%d",i+1); }}} else{ m=1; for(i=0;i<n;i++){ if(m<*(b+i) && max==*(a+i)**(b+i)){ m=*(b+i); }} for(i=0;i<n;i++){ if(max==*(a+i)**(b+i) && m==*(b+i)){ printf("%d",i+1); break; }}} return 0; }
Comments
Post a Comment