-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchooseLaptop.cpp
40 lines (34 loc) · 924 Bytes
/
chooseLaptop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
using namespace std;
struct Laptop {
int speed;
int ram;
int hdd;
int cost;
};
int main() {
int n;
cin >> n;
vector<Laptop> laptops(n);
for (int i = 0; i < n; i++) {
cin >> laptops[i].speed >> laptops[i].ram >> laptops[i].hdd >> laptops[i].cost;
}
int bestChoice = -1;
for (int i = 0; i < n; i++) {
bool outdated = false;
for (int j = 0; j < n; j++) {
if (laptops[j].speed < laptops[i].speed &&
laptops[j].ram < laptops[i].ram &&
laptops[j].hdd < laptops[i].hdd) {
outdated = true;
break;
}
}
if (!outdated && (bestChoice == -1 || laptops[i].cost < laptops[bestChoice].cost)) {
bestChoice = i;
}
}
cout << bestChoice << endl;
return 0;
}