COW201 - Editorial

PROBLEM LINK:

Practice
Contest

Author: Sandeep Singh
Tester: Akash kumar Bhagat
Editorialist: Sandeep Singh

DIFFICULTY:

CAKEWALK

PREREQUISITES:

none

EXPLANATION:

This is a very simple and straightforward problem. You just need to find the price with the minimum corresponding time and in case there are more than 1 price with min time, you need to print the lowest price. This can be done just like finding the minimum in an array with just one extra if statement for the case of multiple minimums.

ALTERNATE EXPLANATION:

You can also sort the array using a custom comparator and print the first value

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for(int i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for(int i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
 
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////
 
int main(){
 
   
   
    int t;
    cin>>t;
    int N, M;
 
    while(t--){
 
        int n;
        cin>>n;
        int price[n],time[n];
 
        scanarr(price,0,n);
        scanarr(time,0,n);
 
        int  ans = price[0];
        int mntm = time[0];
 
        for(int i=1;i<n;i++){
            if(time[i]<=mntm){
                if(time[i]==mntm){
                    ans = min(ans,price[i]);
                }
                else{
                    ans = price[i];
                    mntm = time[i];
                    }
            }
        }
        cout<<ans<<endl;
 
    }
        
} 
1 Like