TABLET - Editorial

PROBLEM LINK:

Practice
Contest

Author: Hasan Jaddouh
Tester: Michael Nematollahi
Editorialist: Hussain Kara Fallah

DIFFICULTY:

Cakewalk

PREREQUISITES:

NONE

PROBLEM:

Chef has visited some tablet shops and listed all of his options. In total, there are N available tablets, numbered 1 through N. For each valid i, the i_{th} tablet has width W_i, height H_i and price P_i.

Chef’s budget is equal to B. He wants to buy the tablet with the largest screen (largest area) as long as its price fits with in the budget.

EXPLANATION:

This problem is a straightforward implementation. Read all the information about the tablets. The screen area of a tablet is equal to the screen’s width multiplied by the screen’s height. Iterate through all tablets and check for each one if its price is less than or equal to B. If so, compare its area to the answer and update the answer to the maximum of them.

To fully understand, it’s better to check one of the implementations attached below.

AUTHOR’S AND TESTER’S SOLUTIONS:

AUTHOR’s solution

TESTER’s solution

Video Editorial : CodeChef February Cook-Off 2019 - Buying New Tablets(TABLET) - YouTube

#include <iostream>

#include<bits/stdc++.h>
#include<algorithm>
#include <boost/math/common_factor.hpp>
#define take(n) long long int n; cin>>n;
#define ll long long 
#define el endl
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define takeArr(A,N) rep(i,0,N) cin>>A[i];
#define Str(S) string S; cin>>S;
#define NET A[i]*20-B[i]*10
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

using namespace std;

int main() {
	// your code goes here
	take(t);
	
	while(t--)
	{
	    int n,b, max_area = 0, flag = 0;
	    cin >> n >> b;
	    
	    int tablets[n][3];
	    
	    for(int i = 0; i < n; i++)
	    {
	        for(int j = 0; j < 3; j++)
	        {
	            cin >> tablets[i][j];
	        }
	    }
	    
	     int test_area = tablets[0][0] * tablets[0][1];
	     
	     for(int i = 0; i < n; i++)
	    {
	            if(tablets[i][2] > b)
	            {
	               flag =1;
	              continue;
	            }  
	            else
	            {
	                flag = 0;
	                if(max_area < test_area)
	                   max_area = test_area;
	               
	               
	                  test_area = tablets[i][0] * tablets [i][1]; 
	                     
	            }
	    }
	    
	    if(flag == 1)
	    {
	        cout << "no tablet" << endl;
	    }
	    else 
	    {
	        cout << max_area << endl;
	    }
	}
	return 0;
}



Can anyone help me with my solution. What is the error in this