Algorithm


B. Choosing Laptop
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya is choosing a laptop. The shop has n laptops to all tastes.

Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.

If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one.

There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him.

Input

The first line contains number n (1 ≤ n ≤ 100).

Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides,

  • speedramhdd and cost are integers
  • 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz
  • 256 ≤ ram ≤ 4096 the RAM volume in megabytes
  • 1 ≤ hdd ≤ 500 is the HDD in gigabytes
  • 100 ≤ cost ≤ 1000 is price in tugriks

All laptops have different prices.

Output

Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.

Examples
input
Copy
5
2100 512 150 200
2000 2048 240 350
2300 1024 200 320
2500 2048 80 300
2000 512 180 150
output
Copy
4
Note

In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <vector>

int main(){

    int n(0); scanf("%d", &n);
    std::vector<std::vector<int> > laptop;
    for(int k = 0; k < n; k++){
        laptop.push_back(std::vector<int>(4,0));
        int speed(0), ram(0), hdd(0), cost(0);
        scanf("%d %d %d %d", &speed, &ram, &hdd, &cost);
        laptop[k][0] = speed;
        laptop[k][1] = ram;
        laptop[k][2] = hdd;
        laptop[k][3] = cost;
    }

    bool *candidate = new bool[n]; for(int k = 0; k  <  n; k++){candidate[k] = 1;}

    for(int a = 0; a < n; a++){
        for(int b = 0; b < n; b++){
            if(a == b){continue;}
            if(laptop[a][0] < laptop[b][0] && laptop[a][1] < laptop[b][1] && laptop[a][2] < laptop[b][2] && laptop[a][3] < laptop[b][3]){candidate[a] = 0; break;}
        }
    }

    int bestLaptop(-1), bestPrice(1001);
    for(int k = 0; k < n; k++){
        if(!candidate[k]){continue;}
        if(laptop[k][3] < bestPrice){bestPrice = laptop[k][3]; bestLaptop = k;}
    }

    printf("%d\n", bestLaptop + 1);

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
2100 512 150 200
2000 2048 240 350
2300 1024 200 320
2500 2048 80 300
2000 512 180 150

Output

x
+
cmd
4
Advertisements

Demonstration


Codeforces Solution-B. Choosing Laptop-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+